From b57ad41b0bff288abb972d75174331ddbfbd4f46 Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 4 Oct 2011 22:57:16 +0200 Subject: [PATCH] [IMP] edi: finish moving edi into new addon bzr revid: odo@openerp.com-20111004205716-u3pdb9th4ma3zkvx --- addons/edi/__openerp__.py | 5 +- addons/edi/models/edi.py | 8 +- addons/edi/models/res_company.py | 74 ++++++++----------- addons/edi/models/res_partner.py | 7 +- addons/edi/security/ir.model.access.csv | 3 + ...edi_documents.yml => edi_partner_test.yml} | 3 +- 6 files changed, 46 insertions(+), 54 deletions(-) create mode 100644 addons/edi/security/ir.model.access.csv rename addons/edi/test/{test_edi_documents.yml => edi_partner_test.yml} (93%) diff --git a/addons/edi/__openerp__.py b/addons/edi/__openerp__.py index d262a5e0434..414dff0e52c 100644 --- a/addons/edi/__openerp__.py +++ b/addons/edi/__openerp__.py @@ -37,8 +37,11 @@ technical OpenERP documentation at http://doc.openerp.com 'author': 'OpenERP SA', 'website': 'http://www.openerp.com', 'depends': ['base'], + 'data': [ + 'security/ir.model.access.csv', + ], 'test': [ - 'test/partner_edi_test.yml', + 'test/edi_partner_test.yml', ], 'installable': True, 'active': False, diff --git a/addons/edi/models/edi.py b/addons/edi/models/edi.py index 734fa61df8f..6191275b2a6 100644 --- a/addons/edi/models/edi.py +++ b/addons/edi/models/edi.py @@ -245,7 +245,7 @@ class EDIMixin(object): if not ext_id: ext_id = existing_id or safe_unique_id(db_uuid, record._name, record.id) # ID is unique cross-db thanks to db_uuid (already included in existing_module) - module = existing_module or "%s:%s" % (record._module, db_uuid) + module = existing_module or "%s:%s" % (record._original_module, db_uuid) _logger.debug("%s: Generating new external ID `%s.%s` for %r", self._name, module, ext_id, record) ir_model_data.create(cr, openerp.SUPERUSER_ID, @@ -257,8 +257,8 @@ class EDIMixin(object): module, ext_id = ext_id.split('.') if not ':' in module: # this record was not previously EDI-imported - assert module == record._module, 'Module mismatch between record and its current'\ - 'external ID' + assert module == record._original_module,\ + 'Mismatching module: expected %s, got %s' % (module, record._original_module) # ID is unique cross-db thanks to db_uuid module = "%s:%s" % (module, db_uuid) @@ -302,7 +302,7 @@ class EDIMixin(object): '__id': ext_id, '__last_update': last_update_for(record), '__model' : record._name, - '__module' : record._module, + '__module' : record._original_module, '__version': version, '__attachments': attachments, } diff --git a/addons/edi/models/res_company.py b/addons/edi/models/res_company.py index 0641ff0e474..a187532347f 100644 --- a/addons/edi/models/res_company.py +++ b/addons/edi/models/res_company.py @@ -19,16 +19,39 @@ # ############################################################################## -#from osv import fields,osv +from osv import fields,osv + +class res_company(osv.osv): + """Helper subclass for res.company providing util methods for working with + companies in the context of EDI import/export. The res.company object + itself is not EDI-exportable""" + _inherit = "res.company" + + def edi_export_address(self, cr, uid, records, edi_address_struct=None, context=None): + """Returns a dict representation of the address of each company record, suitable for + inclusion in an EDI document, and matching the given edi_address_struct if provided. + + :param list(browse_record) records: list of companies to export + :rtype: list(dict) + :return: list of dicts, where each dict contains the address representation for + the company record as the same index in ``records``. + """ + if context is None: + context = {} + res_partner = self.pool.get('res.partner') + res_partner_address = self.pool.get('res.partner.address') + results = [] + for company in records: + res = res_partner.address_get(cr, uid, [company.partner_id.id], ['default', 'contact', 'invoice']) + addr_id = res['invoice'] or res['contact'] or res['default'] + result = {} + if addr_id: + address = res_partner_address.browse(cr, uid, addr_id, context=context) + result = res_partner_address.edi_export(cr, uid, [address], edi_struct=edi_address_struct, context=ctx)[0] + resuls.append(result) + return [] # TODO: CHECK below, seems useless -# -#class res_company(osv.osv): -# """Helper subclass for res.company providing util methods for working with -# companies in the context of EDI import/export. The res.company object -# itself is not EDI-exportable""" -# _inherit = "res.company" -# # def edi_import_as_partner(self, cr, uid, edi_document, values=None, context=None): # """ # import company as a new partner @@ -84,38 +107,3 @@ # edi_document_partner.update(values) # return partner_pool.edi_import(cr, uid, edi_document_partner, context=context) # -# def edi_export_address(self, cr, uid, records, edi_address_struct=None, context=None): -# """Return a dict representation of the address of each company record, suitable for -# inclusion in an EDI document, and matching the given edi_address_struct if provided. -# -# :param list(browse_record) records: list of companies to export -# :rtype: list(dict) -# :return: list of dicts, where each dict contains the address representation for -# the company record as the same index in ``records``. -# """ -# if context is None: -# context = {} -# res_partner = self.pool.get('res.partner') -# res_partner_address = self.pool.get('res.partner.address') -# if edi_address_struct is None: -# edi_address_struct = { -# 'street': True, -# 'street2': True, -# 'zip': True, -# 'city': True, -# 'state_id': True, -# 'country_id': True, -# 'email': True, -# 'phone': True, -# } -# results = [] -# for company in records: -# res = res_partner.address_get(cr, uid, [company.partner_id.id], ['default', 'contact', 'invoice']) -# addr_id = res['invoice'] or res['contact'] or res['default'] -# result = {} -# if addr_id: -# address = res_partner_address.browse(cr, uid, addr_id, context=context) -# result = res_partner_address.edi_export(cr, uid, [address], edi_struct=edi_address_struct, context=ctx)[0] -# results.append(result) -# return results - diff --git a/addons/edi/models/res_partner.py b/addons/edi/models/res_partner.py index e73badf226c..c4d6b5297d8 100644 --- a/addons/edi/models/res_partner.py +++ b/addons/edi/models/res_partner.py @@ -18,7 +18,7 @@ # along with this program. If not, see . # ############################################################################## -from osv import fields,osv +from osv import fields,osv from edi import EDIMixin RES_PARTNER_ADDRESS_EDI_STRUCT = { @@ -48,7 +48,7 @@ class res_partner(osv.osv, EDIMixin): def edi_export(self, cr, uid, records, edi_struct=None, context=None): return super(res_partner,self).edi_export(cr, uid, records, - dict(RES_PARTNER_EDI_STRUCT), + edi_struct or dict(RES_PARTNER_EDI_STRUCT), context=context) class res_partner_address(osv.osv, EDIMixin): @@ -56,9 +56,8 @@ class res_partner_address(osv.osv, EDIMixin): def edi_export(self, cr, uid, records, edi_struct=None, context=None): return super(res_partner_address,self).edi_export(cr, uid, records, - dict(RES_PARTNER_ADDRESS_EDI_STRUCT), + edi_struct or dict(RES_PARTNER_ADDRESS_EDI_STRUCT), context=context) class res_partner_bank(osv.osv, EDIMixin): _inherit = "res.partner.bank" - diff --git a/addons/edi/security/ir.model.access.csv b/addons/edi/security/ir.model.access.csv new file mode 100644 index 00000000000..f1942397ac5 --- /dev/null +++ b/addons/edi/security/ir.model.access.csv @@ -0,0 +1,3 @@ +"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" +"access_ir_edi_all_read","access_ir_edi_all_read","model_edi_document",,1,0,0,0 +"access_ir_edi_employee_create","access_ir_edi_employee_create","model_edi_document","base.group_user",1,0,1,0 \ No newline at end of file diff --git a/addons/edi/test/test_edi_documents.yml b/addons/edi/test/edi_partner_test.yml similarity index 93% rename from addons/edi/test/test_edi_documents.yml rename to addons/edi/test/edi_partner_test.yml index c9695af73e1..e2e497f1344 100644 --- a/addons/edi/test/test_edi_documents.yml +++ b/addons/edi/test/edi_partner_test.yml @@ -6,7 +6,7 @@ with an attached file, check the result, the alter the data and reimport it. - - !python {model: ir.edi.document}: | + !python {model: edi.document}: | import json partner_obj = self.pool.get('res.partner') tokens = self.export_edi(cr, uid, [partner_obj.browse(cr, uid, ref('base.res_partner_agrolait'))]) @@ -16,7 +16,6 @@ # check content of the document assert edi_doc.get('__id').endswith('.res_partner_agrolait'), 'Incorrect external ID' assert edi_doc.get('__model') == 'res.partner', 'Incorrect/Missing __model' - assert edi_doc.get('__module') == 'base', 'Incorrect/Missing __module' assert edi_doc.get('__last_update'), 'Missing __last_update' # try to import the document after changing the name and id, and attaching a