From 1ab22b86cc6825245927cffbddef304dd8fa8a12 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Mon, 24 Oct 2011 16:44:07 +0200 Subject: [PATCH] [IMP] edi: use the new EDIfied res.currency for so/po/invoice EDI bzr revid: odo@openerp.com-20111024144407-3begj09gvfijpel9 --- addons/account/edi/invoice.py | 13 +++++++++++-- addons/account/test/test_edi_invoice.yml | 8 +++++++- addons/purchase/edi/purchase_order.py | 9 +++++---- addons/purchase/test/edi_purchase_order.yml | 8 +++++++- addons/sale/edi/sale_order.py | 9 +++++---- addons/sale/test/edi_sale_order.yml | 8 +++++++- 6 files changed, 42 insertions(+), 13 deletions(-) diff --git a/addons/account/edi/invoice.py b/addons/account/edi/invoice.py index 15fd1327db3..ff9ae27dbaf 100644 --- a/addons/account/edi/invoice.py +++ b/addons/account/edi/invoice.py @@ -54,7 +54,7 @@ INVOICE_EDI_STRUCT = { 'date_due': True, 'partner_id': True, 'payment_term': True, - 'currency_id': True, # TODO: should perhaps include sample rate + rounding + #custom: currency_id 'invoice_line': INVOICE_LINE_EDI_STRUCT, 'tax_line': INVOICE_TAX_LINE_EDI_STRUCT, } @@ -77,6 +77,8 @@ class account_invoice(osv.osv, EDIMixin): 'company_address': res_company.edi_export_address(cr, uid, invoice.company_id, context=context), 'company_paypal_account': invoice.company_id.paypal_account, 'partner_address': res_partner_address.edi_export(cr, uid, [invoice.address_invoice_id], context=context)[0], + + 'currency': self.pool.get('res.currency').edi_export(cr, uid, [invoice.currency_id], context=context), #'company_logo': #TODO }) edi_doc_list.append(edi_doc) @@ -169,7 +171,14 @@ class account_invoice(osv.osv, EDIMixin): """ if context is None: context = {} - self._edi_requires_attributes(('company_id','company_address','type','invoice_line'), edi_document) + self._edi_requires_attributes(('company_id','company_address','type','invoice_line','currency'), edi_document) + + # extract currency info + res_currency = self.pool.get('res.currency') + currency_info = edi_document.pop('currency') + currency_id = res_currency.edi_import(cr, uid, currency_info, context=context) + currency = res_currency.browse(cr, uid, currency_id) + edi_document['currency_id'] = self.edi_m2o(cr, uid, currency, context=context) # change type: out_invoice'<->'in_invoice','out_refund'<->'in_refund' invoice_type = edi_document['type'] diff --git a/addons/account/test/test_edi_invoice.yml b/addons/account/test/test_edi_invoice.yml index 23c29b6ac97..a3861e426b7 100644 --- a/addons/account/test/test_edi_invoice.yml +++ b/addons/account/test/test_edi_invoice.yml @@ -65,7 +65,13 @@ "street": "Chaussee de Namur 40" }, "company_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_company_test11", "Thomson pvt. ltd."], - "currency_id": ["base:b22acf7a-ddcd-11e0-a4db-701a04e25543.EUR", "EUR (€)"], + "currency": { + "__id": "base:b22acf7a-ddcd-11e0-a4db-701a04e25543.EUR", + "__module": "base", + "__model": "res.currency", + "code": "EUR", + "symbol": "€", + }, "partner_id": ["account:b22acf7a-ddcd-11e0-a4db-701a04e25543.res_partner_test20", "Junjun wala"], "partner_address": { "__id": "base:5af1272e-dd26-11e0-b65e-701a04e25543.res_partner_address_7wdsjasdjh", diff --git a/addons/purchase/edi/purchase_order.py b/addons/purchase/edi/purchase_order.py index 91c2d4ed60d..939fd9f9a6e 100644 --- a/addons/purchase/edi/purchase_order.py +++ b/addons/purchase/edi/purchase_order.py @@ -79,7 +79,8 @@ class purchase_order(osv.osv, EDIMixin): 'company_paypal_account': order.company_id.paypal_account, 'partner_address': res_partner_address.edi_export(cr, uid, [order.partner_address_id], context=context)[0], - 'currency_id': self.edi_m2o(cr, uid, order.pricelist_id.currency_id, context=context), + 'currency': self.pool.get('res.currency').edi_export(cr, uid, [order.pricelist_id.currency_id], + context=context)[0], #'company_logo': #TODO }) edi_doc_list.append(edi_doc) @@ -152,15 +153,15 @@ class purchase_order(osv.osv, EDIMixin): return self.edi_m2o(cr, uid, location, context=context) def edi_import(self, cr, uid, edi_document, context=None): - self._edi_requires_attributes(('company_id','company_address','order_line','date_order','currency_id'), edi_document) + self._edi_requires_attributes(('company_id','company_address','order_line','date_order','currency'), edi_document) #import company as a new partner partner_id = self.edi_import_company(cr, uid, edi_document, context=context) # currency for rounding the discount calculations and for the pricelist - currency_id, currency_name = edi_document.pop('currency_id') - currency_id = self.edi_import_relation(cr, uid, 'res.currency', currency_name, currency_id, context=context) res_currency = self.pool.get('res.currency') + currency_info = edi_document.pop('currency') + currency_id = res_currency.edi_import(cr, uid, currency_info, context=context) order_currency = res_currency.browse(cr, uid, currency_id) partner_ref = edi_document.pop('partner_ref', False) diff --git a/addons/purchase/test/edi_purchase_order.yml b/addons/purchase/test/edi_purchase_order.yml index 68519fd0313..f1438bf1ed5 100644 --- a/addons/purchase/test/edi_purchase_order.yml +++ b/addons/purchase/test/edi_purchase_order.yml @@ -47,7 +47,13 @@ "__import_model": "purchase.order", "__version": [6,1,0], "name": "SO008", - "currency_id": ["base:724f93ec-ddd0-11e0-88ec-701a04e25543.EUR", "EUR (€)"], + "currency": { + "__id": "base:724f93ec-ddd0-11e0-88ec-701a04e25543.EUR", + "__module": "base", + "__model": "res.currency", + "code": "EUR", + "symbol": "€", + }, "date_order": "2011-09-13", "partner_id": ["sale:724f93ec-ddd0-11e0-88ec-701a04e25543.res_partner_test22", "Junjun wala"], "partner_address": { diff --git a/addons/sale/edi/sale_order.py b/addons/sale/edi/sale_order.py index 5909eabd121..ba79f543650 100644 --- a/addons/sale/edi/sale_order.py +++ b/addons/sale/edi/sale_order.py @@ -79,7 +79,8 @@ class sale_order(osv.osv, EDIMixin): 'company_paypal_account': order.company_id.paypal_account, 'partner_address': res_partner_address.edi_export(cr, uid, [order.partner_order_id], context=context)[0], - 'currency_id': self.edi_m2o(cr, uid, order.pricelist_id.currency_id, context=context), + 'currency': self.pool.get('res.currency').edi_export(cr, uid, [order.pricelist_id.currency_id], + context=context)[0], 'partner_ref': order.client_order_ref or False, 'notes': order.note or False, #TODO: company_logo @@ -150,15 +151,15 @@ class sale_order(osv.osv, EDIMixin): return self.edi_m2o(cr, uid, pricelist, context=context) def edi_import(self, cr, uid, edi_document, context=None): - self._edi_requires_attributes(('company_id','company_address','order_line','date_order','currency_id'), edi_document) + self._edi_requires_attributes(('company_id','company_address','order_line','date_order','currency'), edi_document) #import company as a new partner partner_id = self._edi_import_company(cr, uid, edi_document, context=context) # currency for rounding the discount calculations and for the pricelist - currency_id, currency_name = edi_document.pop('currency_id') - currency_id = self.edi_import_relation(cr, uid, 'res.currency', currency_name, currency_id, context=context) res_currency = self.pool.get('res.currency') + currency_info = edi_document.pop('currency') + currency_id = res_currency.edi_import(cr, uid, currency_info, context=context) order_currency = res_currency.browse(cr, uid, currency_id) date_order = edi_document['date_order'] diff --git a/addons/sale/test/edi_sale_order.yml b/addons/sale/test/edi_sale_order.yml index 353b3bf1690..184a91081c0 100644 --- a/addons/sale/test/edi_sale_order.yml +++ b/addons/sale/test/edi_sale_order.yml @@ -45,7 +45,13 @@ "__version": [6,1,0], "name": "PO00011", "date_order": "2011-09-12", - "currency_id": ["base:5af1272e-dd26-11e0-b65e-701a04e25543.EUR", "EUR (€)"], + "currency": { + "__id": "base:5af1272e-dd26-11e0-b65e-701a04e25543.EUR", + "__module": "base", + "__model": "res.currency", + "code": "EUR", + "symbol": "€", + }, "company_id": ["base:5af1272e-dd26-11e0-b65e-701a04e25543.main_company", "Client S.A."], "company_address": { "__id": "base:5af1272e-dd26-11e0-b65e-701a04e25543.some_address",