Changeset 2335
- Timestamp:
- 11/05/08 14:58:26 (2 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
ecs/packages/ECS/branches/phonepha/utils/billingTools.py
r2205 r2335 23 23 24 24 from emencia.ecsdb import getMapping 25 from emencia.ecsdb.boundtable import BoundTable 26 from emencia.ecsdb.boundtable import Integer 27 from emencia.ecsdb.boundtable import String 28 from emencia.ecsdb.boundtable import Column 29 from emencia.ecsdb.boundtable import ForeignKey 30 from emencia.ecsdb.boundtable import Float 31 from emencia.ecsdb.ecsdb import getConnector 25 32 from pyPgSQL.PgSQL import PgNumeric 26 33 … … 42 49 current_dir = os.path.dirname(__file__) 43 50 51 phonepha_vatvalue = BoundTable('vatvalue', getConnector(), 52 Column('vat_idvat', Integer, ForeignKey('vat.id'), 53 primary_key=True), 54 Column('geographicalarea_idgeographicalarea', 55 String(15), primary_key=True), 56 Column('value', Float) 57 ) 58 44 59 def prepare_data(idcom): 45 60 """Preparing datas for bill""" … … 49 64 order = Order({'idcommande' : idcom}) 50 65 order.reload() 51 if order.payment_mode is not None:52 label_payment_mode = "label_payment_mode_%s" % order.payment_mode53 else:54 label_payment_mode = "label_payment_mode_other"66 #if order.payment_mode is not None: 67 # label_payment_mode = "label_payment_mode_%s" % order.payment_mode 68 #else: 69 # label_payment_mode = "label_payment_mode_other" 55 70 56 71 lang = TranslationManager() 57 label_payment_mode = lang.translate(label_payment_mode,58 domain='backoffice',59 language=language)72 #label_payment_mode = lang.translate(label_payment_mode, 73 # domain='backoffice', 74 # language=language) 60 75 61 76 client = Customer({'idclient' : order.client_idclient}) … … 73 88 bills = Bill.search(query={'commande_idcommande' : order.idcommande}) 74 89 bill = None 75 76 90 if bills: 77 91 # XXX TZ We should not have several commands here 78 92 # this is a bug 79 93 bill = bills[0] 80 billline = BillLine.search(query={'bill_idbill' : bill['idbill']})81 94 else: 82 bill = {'amountbill': order.products['total'], 83 'deliverycostbill': order.products['delivery_price_amount'], 84 'netoftaxbill': order.products['total_net_of_tax'], 85 'datebill': order.datecommande, 86 'referencebill': 'BC'+order.referencecommande, 87 'payed': False, 88 'reductionbill': order.products['total_reduction'], 89 'itemnumberbill': order.products['total_quantity'], 90 'deliverybill': order.delivery_price['libelle_idlibelle_translation'], 91 'adresse_idadresse_livraison': order.adresse_idadresse_livraison, 92 'adresse_idadresse_facturation': order.adresse_idadresse_facturation} 93 billline = [] 94 for line in order.products['products']: 95 line = {'unitpricebillline': line['price'], 96 'quantitybillline': line['quantity'], 97 'referencebillline': line['reference'], 98 'labelbillline': line['libelle_idlibelle_translation'], 99 'amountbillline': line['price'] * line['quantity'], 100 'packagingbillline': line['conditionnement']} 101 billline.append(line) 95 return None 102 96 103 97 # XXX TZ : about the comment above, please explain what is the … … 105 99 106 100 #Â the above code is pretty hugly, but done for now without mapping 101 billline = BillLine.search(query={'bill_idbill' : bill['idbill']}) 107 102 amountart = bill['amountbill'] - bill['deliverycostbill'] 108 103 bill['taxbill'] = round(amountart - bill['netoftaxbill'], 2) 109 bill['label_payment_mode'] = label_payment_mode104 #bill['label_payment_mode'] = label_payment_mode 110 105 adrs_facts = Adresse.search(query={'idadresse' : 111 106 bill['adresse_idadresse_facturation']}, … … 148 143 for line in billline: 149 144 product = ProductBootique.search(query={'reference': line['referencebillline']})[0] 150 vat_value = getMapping('vatvalue').select(vat_vat_id=product['vat_idvat'], 151 geographicalzone_geographicalzone_iso=\ 152 billing_country['geographicalzone_geographicalzone_iso'] 153 ).fetchall()[0].value 154 if vat_value in total_by_vat: 155 total_by_vat[vat_value] += line['unitpricebillline'] * line['quantitybillline'] 156 else: 157 total_by_vat[vat_value] = line['unitpricebillline'] * line['quantitybillline'] 158 line['vat_value'] = vat_value 159 line['unitpricehtbillline'] = line['unitpricebillline'] / (1 + vat_value / 100) 160 line['amounthtbillline'] = line['unitpricehtbillline'] * line['quantitybillline'] 161 if line['packagingbillline'] == '1': 162 line['packagingbillline'] = '' 163 else: 164 line['packagingbillline'] = " - %sg" % line['packagingbillline'] 145 146 vat_value = phonepha_vatvalue.select(vat_vat_id=product['vat_idvat']).fetchall()[0].value 147 line['unitpricehtbillline'] = float(line['unitpricebillline']) / float(((100 + vat_value) / 100)) 148 line['amounthtbillline'] = "%.2f" % float(line['unitpricehtbillline'] * line['quantitybillline']) 149 line['unitpricehtbillline'] = "%.2f" % line['unitpricehtbillline'] 150 165 151 for key, value in line.iteritems(): 166 152 if isinstance(value, PgNumeric): … … 200 186 201 187 data = prepare_data(idcom) 188 202 189 if data is None: 203 190 return None, None … … 240 227 xml['amountbill'] = "%.2f" % float(data['amountart'] + xml['deliverycostbill']) 241 228 xml['lines'] = data['billline'] 242 xml['by_vat'] = data['by_vat'] 229 230 #xml['netoftaxbill'] = round(xml['netoftaxbill'], 2) 231 243 232 xml['amounttax'] = xml['taxbill'] 244 233 xml['customer_id'] = data['client'].idclient ecs/packages/ECS/branches/phonepha/utils/templates/Billing_pdf.pt
r1908 r2335 174 174 <pageGraphics> 175 175 <image x="5mm" y="260mm" file="logo.jpg" width="300mm" height="30mm" /> 176 <drawCentredString x="100mm" y="1cm"> AZSPORTS</drawCentredString>177 <drawCentredString x="100mm" y="0.6cm"> 63 bd de ménilmontant - 75011 Paris</drawCentredString>178 <drawCentredString x="100mm" y="0.1cm">T él : 01 48 07 33 00 - SIRET : 443 005 103 00025</drawCentredString>176 <drawCentredString x="100mm" y="1cm">TFT Souve, 71190 Thil France</drawCentredString> 177 <drawCentredString x="100mm" y="0.6cm">SIRET : 500 554 019</drawCentredString> 178 <drawCentredString x="100mm" y="0.1cm">TVA : FR25500554019</drawCentredString> 179 179 </pageGraphics> 180 180 … … 195 195 <pageTemplate id="others"> 196 196 <pageGraphics> 197 <drawCentredString x="100mm" y="2cm"> AZSPORTS</drawCentredString>198 <drawCentredString x="100mm" y="1.5cm"> 63 bd de ménilmontant - 75011 Paris</drawCentredString>199 <drawCentredString x="100mm" y="0.5cm">T él : 01 48 07 33 11 - SIRET : 443 005 103 00025</drawCentredString>197 <drawCentredString x="100mm" y="2cm">TFT Souve, 71190 Thil France</drawCentredString> 198 <drawCentredString x="100mm" y="1.5cm">SIRET : 500 554 019</drawCentredString> 199 <drawCentredString x="100mm" y="0.5cm">TVA : FR25500554019</drawCentredString> 200 200 </pageGraphics> 201 201 <frame id="products" x1="2mm" y1="2.5cm" width="20cm"
