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) on 2014-05-22
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 - Agile BG (community) Resubmit on 2014-07-23
Yannick Vaucher @ Camptocamp 2014-05-22 Disapprove on 2014-05-23
Lara (Therp) (community) test Approve on 2014-05-22
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.
Lara (Therp) (lfreeke) :
review: Approve (test)

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

firstname_display_name_trigger should already fix this issue.

Thus I disapprove it.

review: Disapprove

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: Resubmit

Unmerged revisions

38. By Ronald Portier (Therp) on 2014-05-22

[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
1=== modified file 'partner_firstname/partner.py'
2--- partner_firstname/partner.py 2014-02-18 17:09:53 +0000
3+++ partner_firstname/partner.py 2014-05-22 12:13:06 +0000
4@@ -45,6 +45,28 @@
5 res[rec['id']] = fullname
6 return res
7
8+ def _force_display_name(self, cr, uid, ids, context=None):
9+ '''Column display_name might, or might not exist in res.partner,
10+ depending on modules installed. At present it is added by the
11+ account_report_company module. If it is present, we will call the
12+ _display_name_compute function and use its return value to update the
13+ database directly.'''
14+ if 'display_name' in self._columns:
15+ try:
16+ values = self._display_name_compute(
17+ cr, uid, ids, 'display_name', False, context=context)
18+ except AttributeError:
19+ # just in case method does not exist:
20+ context = dict(context or {})
21+ context.pop('show_address', None)
22+ values = dict(self.name_get(cr, uid, ids, context=context))
23+ for key, value in values.iteritems():
24+ statement = (
25+ "update res_partner set display_name='%s' where id=%d"
26+ % (value, key)
27+ )
28+ cr.execute(statement)
29+
30 def _write_name(self, cursor, uid, partner_id, field_name, field_value, arg, context=None):
31 """
32 Try to reverse the effect of _compute_name_custom:
33@@ -83,6 +105,12 @@
34 del(default['name'])
35 return super(ResPartner, self).copy_data(cr, uid, _id, default, context=context)
36
37+ def write(self, cr, uid, ids, vals, context=None):
38+ result = super(ResPartner, self).write(
39+ cr, uid, ids, vals, context=context)
40+ self._force_display_name(cr, uid, ids, context=context)
41+ return result
42+
43 def create(self, cursor, uid, vals, context=None):
44 """
45 To support data backward compatibility we have to keep this overwrite even if we
46@@ -95,7 +123,10 @@
47 corr_vals['lastname'] = corr_vals['name']
48 del(corr_vals['name'])
49 to_use = corr_vals
50- return super(ResPartner, self).create(cursor, uid, to_use, context=context)
51+ result = super(ResPartner, self).create(
52+ cursor, uid, to_use, context=context)
53+ self._force_display_name(cursor, uid, [result], context=context)
54+ return result
55
56 _columns = {'name': fields.function(_compute_name_custom, string="Name",
57 type="char", store=True,

Subscribers

People subscribed via source and target branches

to status/vote changes: