openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #06923
[Merge] lp:~therp-nl/partner-contact-management/7.0_1184983_compute_display_name into lp:partner-contact-management
Ronald Portier (Therp) has proposed merging lp:~therp-nl/partner-contact-management/7.0_1184983_compute_display_name into lp:partner-contact-management.
Requested reviews:
Partner and Contact Core Editors (partner-contact-core-editors)
Related bugs:
Bug #1184983 in Partner and Contact Management: "partner_firstname - display_name is not updated when a partner is modified"
https://bugs.launchpad.net/partner-contact-management/+bug/1184983
For more details, see:
https://code.launchpad.net/~therp-nl/partner-contact-management/7.0_1184983_compute_display_name/+merge/220629
Force update of display_name on res.partner - but only if column present - on all create and write actions.
--
https://code.launchpad.net/~therp-nl/partner-contact-management/7.0_1184983_compute_display_name/+merge/220629
Your team Partner and Contact Core Editors is requested to review the proposed merge of lp:~therp-nl/partner-contact-management/7.0_1184983_compute_display_name into lp:partner-contact-management.
=== modified file 'partner_firstname/partner.py'
--- partner_firstname/partner.py 2014-02-18 17:09:53 +0000
+++ partner_firstname/partner.py 2014-05-22 12:13:06 +0000
@@ -45,6 +45,28 @@
res[rec['id']] = fullname
return res
+ def _force_display_name(self, cr, uid, ids, context=None):
+ '''Column display_name might, or might not exist in res.partner,
+ depending on modules installed. At present it is added by the
+ account_report_company module. If it is present, we will call the
+ _display_name_compute function and use its return value to update the
+ database directly.'''
+ if 'display_name' in self._columns:
+ try:
+ values = self._display_name_compute(
+ cr, uid, ids, 'display_name', False, context=context)
+ except AttributeError:
+ # just in case method does not exist:
+ context = dict(context or {})
+ context.pop('show_address', None)
+ values = dict(self.name_get(cr, uid, ids, context=context))
+ for key, value in values.iteritems():
+ statement = (
+ "update res_partner set display_name='%s' where id=%d"
+ % (value, key)
+ )
+ cr.execute(statement)
+
def _write_name(self, cursor, uid, partner_id, field_name, field_value, arg, context=None):
"""
Try to reverse the effect of _compute_name_custom:
@@ -83,6 +105,12 @@
del(default['name'])
return super(ResPartner, self).copy_data(cr, uid, _id, default, context=context)
+ def write(self, cr, uid, ids, vals, context=None):
+ result = super(ResPartner, self).write(
+ cr, uid, ids, vals, context=context)
+ self._force_display_name(cr, uid, ids, context=context)
+ return result
+
def create(self, cursor, uid, vals, context=None):
"""
To support data backward compatibility we have to keep this overwrite even if we
@@ -95,7 +123,10 @@
corr_vals['lastname'] = corr_vals['name']
del(corr_vals['name'])
to_use = corr_vals
- return super(ResPartner, self).create(cursor, uid, to_use, context=context)
+ result = super(ResPartner, self).create(
+ cursor, uid, to_use, context=context)
+ self._force_display_name(cursor, uid, [result], context=context)
+ return result
_columns = {'name': fields.function(_compute_name_custom, string="Name",
type="char", store=True,
Follow ups