From f72fc4acfa5ae29504621fdda7d8a7e20195068a Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Thu, 23 Feb 2012 14:53:47 +0100 Subject: [PATCH] [IMP] base/res: simplify code and fix res_partner.address_get bzr revid: rco@openerp.com-20120223135347-ff3h8eikq2xj7x4q --- openerp/addons/base/res/res_bank.py | 11 ++++++----- openerp/addons/base/res/res_partner.py | 14 ++++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/openerp/addons/base/res/res_bank.py b/openerp/addons/base/res/res_bank.py index 7f6c11abb99..891794cb99c 100644 --- a/openerp/addons/base/res/res_bank.py +++ b/openerp/addons/base/res/res_bank.py @@ -108,6 +108,7 @@ class res_partner_bank(osv.osv): value = '' if not context.get('address'): return value + for address in self.pool.get('res.partner').resolve_o2m_commands_to_record_dicts( cursor, user, 'address', context['address'], ['type', field], context=context): @@ -218,11 +219,11 @@ class res_partner_bank(osv.osv): if partner_id: part = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context) result['owner_name'] = part.name - result['street'] = part and part.street or False - result['city'] = part and part.city or False - result['zip'] = part and part.zip or False - result['country_id'] = part and part.country_id and part.country_id.id or False - result['state_id'] = part and part.state_id and part.state_id.id or False + result['street'] = part.street or False + result['city'] = part.city or False + result['zip'] = part.zip or False + result['country_id'] = part.country_id.id + result['state_id'] = part.state_id.id return {'value': result} res_partner_bank() diff --git a/openerp/addons/base/res/res_partner.py b/openerp/addons/base/res/res_partner.py index b5de96f09b4..c6354fa8cd2 100644 --- a/openerp/addons/base/res/res_partner.py +++ b/openerp/addons/base/res/res_partner.py @@ -272,19 +272,21 @@ class res_partner(osv.osv): def address_get(self, cr, uid, ids, adr_pref=None): if adr_pref is None: adr_pref = ['default'] - address_ids = self.search(cr, uid, [('parent_id', 'in', ids)]) - address_rec = self.read(cr, uid, address_ids, ['type']) - res = list((addr['type'],addr['id']) for addr in address_rec) - adr = dict(res) + # retrieve addresses from the partner itself and its children + res = [] + for p in self.browse(cr, uid, ids, context): + res.append((p.type, p.id)) + res.extend((c.type, c.id) for c in p.child_ids) + addr = dict(reversed(res)) # get the id of the (first) default address if there is one, # otherwise get the id of the first address in the list if res: - default_address = adr.get('default', res[0][1]) + default_address = addr.get('default', res[0][1]) else: default_address = False result = {} for a in adr_pref: - result[a] = adr.get(a, default_address) + result[a] = addr.get(a, default_address) return result def gen_next_ref(self, cr, uid, ids):