[FIX] res.partner.address_get: default to partner being looked up rather than company when no match is found at all (and no "default" exists)

Using the commercial entity is not a very good default choice
in many cases. If a new contact is created on-the-fly for a
new document (e.g. sales order), his/her company may be an
empty shell and/or a large corporation that should not be
directly used for e.g. billing/invoicing purposed.
Once a contact/company is set to "invoicing" or "delivery"
we use it, but in other cases we stick to the provided
partner/contact as a saner default.
This should not change anything for cases where advanced
contact management is used and proper address types are
set.

bzr revid: odo@openerp.com-20130410121536-vm93o6vxhi3b8feu
This commit is contained in:
Olivier Dony 2013-04-10 14:15:36 +02:00
parent 70fbc25d93
commit 9dbe29b2b5
2 changed files with 8 additions and 8 deletions

View File

@ -616,7 +616,7 @@ class res_partner(osv.osv, format_address):
through descendants within company boundaries (stop at entities flagged ``is_company``)
then continuing the search at the ancestors that are within the same company boundaries.
Defaults to partners of type ``'default'`` when the exact type is not found, or to the
commercial entity if no type ``'default'`` is found either. """
provided partner itself if no type ``'default'`` is found either. """
adr_pref = set(adr_pref or [])
if 'default' not in adr_pref:
adr_pref.add('default')
@ -643,8 +643,8 @@ class res_partner(osv.osv, format_address):
break
current_partner = current_partner.parent_id
# default to type 'default' or the commercial_entity of the main/last partner
default = result.get('default', partner.commercial_id.id)
# default to type 'default' or the partner itself
default = result.get('default', partner.id)
for adr_type in adr_pref:
result[adr_type] = result.get(adr_type) or default
return result

View File

@ -90,8 +90,8 @@ class test_base(common.TransactionCase):
def test_40_res_partner_address_getc(self):
""" Test address_get address resolution mechanism: it should first go down through descendants,
stopping when encountering another is_copmany entity, then go up, stopping again at the first
is_company entity or the root ancestor and if nothing matches, it should use the commercial entity
of the partner (which could be itself) """
is_company entity or the root ancestor and if nothing matches, it should use the provided partner
itself """
cr, uid = self.cr, self.uid
elmtree = self.res_partner.browse(cr, uid, self.res_partner.name_create(cr, uid, 'Elmtree')[0])
branch1 = self.res_partner.browse(cr, uid, self.res_partner.create(cr, uid, {'name': 'Branch 1',
@ -124,13 +124,13 @@ class test_base(common.TransactionCase):
'invoice': leaf10.id,
'contact': branch1.id,
'other': branch11.id,
'default': branch1.id}, 'Invalid address resolution')
'default': leaf111.id}, 'Invalid address resolution')
self.assertEqual(self.res_partner.address_get(cr, uid, [branch11.id], ['delivery', 'invoice', 'contact', 'other', 'default']),
{'delivery': leaf111.id,
'invoice': leaf10.id,
'contact': branch1.id,
'other': branch11.id,
'default': branch1.id}, 'Invalid address resolution')
'default': branch11.id}, 'Invalid address resolution')
# go down, stop at at all child companies
self.assertEqual(self.res_partner.address_get(cr, uid, [elmtree.id], ['delivery', 'invoice', 'contact', 'other', 'default']),
@ -179,7 +179,7 @@ class test_base(common.TransactionCase):
self.assertEqual(self.res_partner.address_get(cr, uid, [elmtree.id], []),
{'default': elmtree.id}, 'Invalid address resolution, no default means commercial entity ancestor')
self.assertEqual(self.res_partner.address_get(cr, uid, [leaf111.id], []),
{'default': branch1.id}, 'Invalid address resolution, no default means commercial entity ancestor')
{'default': leaf111.id}, 'Invalid address resolution, no default means contact itself')
branch11.write({'type': 'default'})
self.assertEqual(self.res_partner.address_get(cr, uid, [leaf111.id], []),
{'default': branch11.id}, 'Invalid address resolution, branch11 should now be default')