Skip to content

Commit

Permalink
[FIX] partner: fix update for company address
Browse files Browse the repository at this point in the history
  * when writing an empty value to ADDRESS_FIELDS, that value
    should also be propagated by update_address()

  * when creating a contact from a company form view, even with
    'use_company_address', company's contact address remains empty. We
    now force adding missing address fields uppon creation when default
    'use_company_address' is True.

bzr revid: [email protected]
  • Loading branch information
xavieralt committed Mar 29, 2013
1 parent 42e713a commit 43cc95c
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions openerp/addons/base/res/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,16 +381,30 @@ def write(self, cr, uid, ids, vals, context=None):

def create(self, cr, uid, vals, context=None):
if context is None:
context={}
context = {}
# Update parent and siblings records
if vals.get('parent_id') and vals.get('use_parent_address'):
domain_siblings = [('parent_id', '=', vals['parent_id']), ('use_parent_address', '=', True)]
update_ids = [vals['parent_id']] + self.search(cr, uid, domain_siblings, context=context)
self.update_address(cr, uid, update_ids, vals, context)
return super(res_partner,self).create(cr, uid, vals, context=context)
if vals.get('parent_id'):
if 'use_parent_address' in vals:
use_parent_address = vals['use_parent_address']
else:
use_parent_address = self.default_get(cr, uid, ['use_parent_address'], context=context)['use_parent_address']

if use_parent_address:
domain_siblings = [('parent_id', '=', vals['parent_id']), ('use_parent_address', '=', True)]
update_ids = [vals['parent_id']] + self.search(cr, uid, domain_siblings, context=context)
self.update_address(cr, uid, update_ids, vals, context)

# add missing address keys
onchange_values = self.onchange_address(cr, uid, [], use_parent_address,
vals['parent_id'], context=context).get('value') or {}
vals.update(dict((key, value)
for key, value in onchange_values.iteritems()
if key in ADDRESS_FIELDS and key not in vals))

return super(res_partner, self).create(cr, uid, vals, context=context)

def update_address(self, cr, uid, ids, vals, context=None):
addr_vals = dict((key, vals[key]) for key in POSTAL_ADDRESS_FIELDS if vals.get(key))
addr_vals = dict((key, vals[key]) for key in POSTAL_ADDRESS_FIELDS if key in vals)
if addr_vals:
return super(res_partner, self).write(cr, uid, ids, addr_vals, context)

Expand Down

0 comments on commit 43cc95c

Please sign in to comment.