[IMP] base/res: simplify code and fix res_partner.address_get
bzr revid: rco@openerp.com-20120223135347-ff3h8eikq2xj7x4q
This commit is contained in:
parent
e06a8dbd0e
commit
f72fc4acfa
|
@ -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()
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue