Merge lp:~therp-nl/partner-contact-management/7.0_1184983_compute_display_name into lp:~partner-contact-core-editors/partner-contact-management/7.0

Proposed by Ronald Portier (Therp)
Status: Needs review
Proposed branch: lp:~therp-nl/partner-contact-management/7.0_1184983_compute_display_name
Merge into: lp:~partner-contact-core-editors/partner-contact-management/7.0
Diff against target: 57 lines (+32/-1)
1 file modified
partner_firstname/partner.py (+32/-1)
To merge this branch: bzr merge lp:~therp-nl/partner-contact-management/7.0_1184983_compute_display_name
Reviewer Review Type Date Requested Status
Lorenzo Battistini (community) Needs Resubmitting
Yannick Vaucher @ Camptocamp Disapprove
Lara (Therp) (community) test Approve
Review via email: mp+220629@code.launchpad.net

Description of the change

Force update of display_name on res.partner - but only if column present - on all create and write actions.

To post a comment you must log in.
Revision history for this message
Lara (Therp) (lfreeke) :
review: Approve (test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Doesn't the module firstname_display_name_trigger already does this job?

There is already a trigger in it to recompute display_name.

review: Needs Information
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

firstname_display_name_trigger should already fix this issue.

Thus I disapprove it.

review: Disapprove
Revision history for this message
Lorenzo Battistini (elbati) wrote :

This project is now hosted on https://github.com/OCA/partner-contact. Please move your proposal there. This guide may help you https://github.com/OCA/maintainers-tools/wiki/How-to-move-a-Merge-Proposal-to-GitHub

review: Needs Resubmitting

Unmerged revisions

38. By Ronald Portier (Therp)

[FIX] Make sure display_name on res.partner is always updated whn that
    field exists on the model.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== 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 @@
45 res[rec['id']] = fullname45 res[rec['id']] = fullname
46 return res46 return res
4747
48 def _force_display_name(self, cr, uid, ids, context=None):
49 '''Column display_name might, or might not exist in res.partner,
50 depending on modules installed. At present it is added by the
51 account_report_company module. If it is present, we will call the
52 _display_name_compute function and use its return value to update the
53 database directly.'''
54 if 'display_name' in self._columns:
55 try:
56 values = self._display_name_compute(
57 cr, uid, ids, 'display_name', False, context=context)
58 except AttributeError:
59 # just in case method does not exist:
60 context = dict(context or {})
61 context.pop('show_address', None)
62 values = dict(self.name_get(cr, uid, ids, context=context))
63 for key, value in values.iteritems():
64 statement = (
65 "update res_partner set display_name='%s' where id=%d"
66 % (value, key)
67 )
68 cr.execute(statement)
69
48 def _write_name(self, cursor, uid, partner_id, field_name, field_value, arg, context=None):70 def _write_name(self, cursor, uid, partner_id, field_name, field_value, arg, context=None):
49 """71 """
50 Try to reverse the effect of _compute_name_custom:72 Try to reverse the effect of _compute_name_custom:
@@ -83,6 +105,12 @@
83 del(default['name'])105 del(default['name'])
84 return super(ResPartner, self).copy_data(cr, uid, _id, default, context=context)106 return super(ResPartner, self).copy_data(cr, uid, _id, default, context=context)
85107
108 def write(self, cr, uid, ids, vals, context=None):
109 result = super(ResPartner, self).write(
110 cr, uid, ids, vals, context=context)
111 self._force_display_name(cr, uid, ids, context=context)
112 return result
113
86 def create(self, cursor, uid, vals, context=None):114 def create(self, cursor, uid, vals, context=None):
87 """115 """
88 To support data backward compatibility we have to keep this overwrite even if we116 To support data backward compatibility we have to keep this overwrite even if we
@@ -95,7 +123,10 @@
95 corr_vals['lastname'] = corr_vals['name']123 corr_vals['lastname'] = corr_vals['name']
96 del(corr_vals['name'])124 del(corr_vals['name'])
97 to_use = corr_vals125 to_use = corr_vals
98 return super(ResPartner, self).create(cursor, uid, to_use, context=context)126 result = super(ResPartner, self).create(
127 cursor, uid, to_use, context=context)
128 self._force_display_name(cursor, uid, [result], context=context)
129 return result
99130
100 _columns = {'name': fields.function(_compute_name_custom, string="Name",131 _columns = {'name': fields.function(_compute_name_custom, string="Name",
101 type="char", store=True,132 type="char", store=True,

Subscribers

People subscribed via source and target branches

to status/vote changes: