[IMP] res.partner.edi: working edi implementation for res.partner + smoke test
bzr revid: odo@openerp.com-20111004142951-klopyd7zn5sxf65g
This commit is contained in:
parent
3a224dfc06
commit
4900560931
|
@ -21,18 +21,45 @@
|
|||
from osv import fields,osv
|
||||
from base.ir import ir_edi
|
||||
|
||||
RES_PARTNER_ADDRESS_EDI_STRUCT = {
|
||||
'name': True,
|
||||
'email': True,
|
||||
'street': True,
|
||||
'street2': True,
|
||||
'zip': True,
|
||||
'city': True,
|
||||
'country_id': True,
|
||||
'state_id': True,
|
||||
'phone': True,
|
||||
'fax': True,
|
||||
'mobile': True,
|
||||
}
|
||||
|
||||
RES_PARTNER_EDI_STRUCT = {
|
||||
'name': True,
|
||||
'ref': True,
|
||||
'lang': True,
|
||||
'website': True,
|
||||
'address': RES_PARTNER_ADDRESS_EDI_STRUCT
|
||||
}
|
||||
|
||||
|
||||
class res_partner(osv.osv, ir_edi.edi):
|
||||
_inherit = "res.partner"
|
||||
|
||||
res_partner()
|
||||
|
||||
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),
|
||||
context=context)
|
||||
|
||||
class res_partner_address(osv.osv, ir_edi.edi):
|
||||
_inherit = "res.partner.address"
|
||||
|
||||
res_partner_address()
|
||||
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),
|
||||
context=context)
|
||||
|
||||
class res_partner_bank(osv.osv, ir_edi.edi):
|
||||
_inherit = "res.partner.bank"
|
||||
|
||||
res_partner_bank()
|
||||
|
||||
|
|
|
@ -1,47 +1,43 @@
|
|||
-
|
||||
I create partner
|
||||
In order to test the basic EDI system, I will export a partner,
|
||||
modify the exported EDI document to add an attachment and change
|
||||
the data, and then re-import it and re-export it.
|
||||
|
||||
with an attached file, check the result, the alter the data
|
||||
and reimport it.
|
||||
-
|
||||
!record {model: res.partner, id: res_partner_test33}:
|
||||
name: Ivan
|
||||
title: base.res_partner_title_sir
|
||||
website: www.openerp.com
|
||||
address:
|
||||
- type: default
|
||||
name: Davidson
|
||||
street: M.G. Road
|
||||
zip: 354562
|
||||
city: Alhabad
|
||||
phone: +91 985764653
|
||||
supplier: False
|
||||
customer: True
|
||||
company_id: base.main_company
|
||||
|
||||
-
|
||||
I am creating one Document to be attached in partner ".
|
||||
-
|
||||
!record {model: 'ir.attachment', id: document_4}:
|
||||
name : "My partner document"
|
||||
res_model : res.partner
|
||||
type : binary
|
||||
|
||||
-
|
||||
I attach a pdf file in "My partner document"
|
||||
-
|
||||
!python {model: 'ir.attachment'}: |
|
||||
import addons
|
||||
import base64
|
||||
pdf_file = open(addons.get_module_resource('base','test', 'partner.pdf'))
|
||||
self.write(cr, uid, [ref("document_4")], {'res_id':ref("res_partner_test33"), 'datas_fname': 'partner.pdf', 'datas' : base64.encodestring(pdf_file.read())}, context)
|
||||
|
||||
-
|
||||
I am Tesing of EDI functionality. so first export partner and than import it again.
|
||||
-
|
||||
|
||||
!python {model: ir.edi.document}: |
|
||||
import json
|
||||
partner_obj = self.pool.get('res.partner')
|
||||
partners = [partner_obj.browse(cr, uid, ref("res_partner_test33"))]
|
||||
tokens = self.export_edi(cr, uid, partners)
|
||||
assert tokens, 'Token is not generated.'
|
||||
document = self.get_document(cr, uid, tokens[0], context=context)
|
||||
a = self.import_edi(cr, uid, edi_document = document)
|
||||
tokens = self.export_edi(cr, uid, [partner_obj.browse(cr, uid, ref('base.res_partner_agrolait'))])
|
||||
doc = self.get_document(cr, uid, tokens[0], context=context)
|
||||
edi_doc, = json.loads(doc)
|
||||
|
||||
# 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
|
||||
# file, and check that a new partner is returned
|
||||
edi_doc['__id'] = 'base:xxd37f8a-xx55-11e0-xxdd-xx81124c8b50.res_partner_xxx'
|
||||
edi_doc['name'] = 'AgroMilk'
|
||||
attachment = {
|
||||
'name': 'Test file',
|
||||
'file_name': 'test.png',
|
||||
'content': 'iVBORw0KGgoAAAANSUhEUgAAAA4AAAAKCAYAAACE2W/HAAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oIDQ84BkjLWAYAAACNSURBVCjPjZKxDUJBDEOf/wbUbEHDhkxAzRjUDECBhMQYjIApuPBNpK+PpUinOPYll5Nt1iCJXifbSPpJZtHgXLUdu0FWpMEt87a/xtsmqjjNetPFyhuWYFuj7RcgQBNwXNGdw2CqY85yXWi5z7YBnmRyEHvg0YSXrLE9P30nwugOHHr+s5va4x+fofAGm1+JjnJICm0AAAAASUVORK5CYII=',
|
||||
}
|
||||
edi_doc['__attachments'] = [attachment]
|
||||
doc = json.dumps([edi_doc])
|
||||
result, = self.import_edi(cr, uid, edi_document=doc)
|
||||
assert result[0] == 'res.partner' and result[1] > ref('base.res_partner_agrolait'),\
|
||||
"Expected (%r,> %r) after import 1, got %r" % ('res.partner', ref('base.res_partner_agrolait'), result)
|
||||
|
||||
# export the same partner we just created, and see if the output matches the input
|
||||
tokens = self.export_edi(cr, uid, [partner_obj.browse(cr, uid, result[1])])
|
||||
doc_output = self.get_document(cr, uid, tokens[0], context=context)
|
||||
edi_doc_output, = json.loads(doc_output)
|
||||
for attribute in ('__model', '__module', '__id', 'name', '__attachments'):
|
||||
assert edi_doc_output.get(attribute) == edi_doc.get(attribute), \
|
||||
'Incorrect value for %s, expected %r, got %r' % (attribute, edi_doc.get(attribute), edi_doc_output.get(attribute))
|
Loading…
Reference in New Issue