Merge lp:~camptocamp/partner-contact-management/7.0-add-firstname_display_name_trigger into lp:~partner-contact-core-editors/partner-contact-management/7.0

Proposed by Yannick Vaucher @ Camptocamp
Status: Merged
Approved by: Guewen Baconnier @ Camptocamp
Approved revision: 25
Merged at revision: 22
Proposed branch: lp:~camptocamp/partner-contact-management/7.0-add-firstname_display_name_trigger
Merge into: lp:~partner-contact-core-editors/partner-contact-management/7.0
Diff against target: 192 lines (+166/-0)
5 files modified
firstname_display_name_trigger/__init__.py (+24/-0)
firstname_display_name_trigger/__openerp__.py (+41/-0)
firstname_display_name_trigger/res_partner.py (+65/-0)
firstname_display_name_trigger/tests/__init__.py (+5/-0)
firstname_display_name_trigger/tests/test_display_name.py (+31/-0)
To merge this branch: bzr merge lp:~camptocamp/partner-contact-management/7.0-add-firstname_display_name_trigger
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review, no test Approve
Alexandre Fayolle - camptocamp code review, no test Approve
Review via email: mp+165354@code.launchpad.net
To post a comment you must log in.
22. By Yannick Vaucher @ Camptocamp

[ADD] firstname_display_name - python unit tests

23. By Yannick Vaucher @ Camptocamp

[ADD] firstnamt_display_name_trigger - name_get overwrite to by pass reading of name

24. By Alexandre Fayolle - camptocamp

[IMP] update description

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

LGTM

review: Approve (code review, no test)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Could you put it in the 'Hidden' module category? (Or does this category disappeared in OpenERP 7?)

l.126-127: replace is done twice. It assumes there is good reason but the 'why' would deserve to be explained as a comment above the lines I think

Congrats for the tests :-)

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

For the name_get function, it is a copy of official name_get but with few changes about constructing the name.

The address concatenation where double \n are removed was taken from there. A cleanest way might be to ask for a hook to create the name.

I also found the l.126-127 quite strange but I assume there are few chances that an address has more than 4 empty lines, even though it would be possible as there is no limit in country address format field.

http://bazaar.launchpad.net/~openerp/openobject-server/7.0/view/head:/openerp/addons/base/res/res_partner.py#L524

I'll check about Hidden category.

Revision history for this message
Eric Caudal - www.elico-corp.com (elicoidal) wrote :

Not sure it is relevant but in China, family name is the first to be
displayed.

For me it should be part of the localization or address setup
Eric CAUDAL

Eric Caudal
/CEO/
--
*Elico Corporation, Shanghai branch
/OpenERP Premium Certified Training Partner/ *
Cell: + 86 186 2136 1670
Office: + 86 21 6211 8017/27/37
Skype: elico.corp
<email address hidden> <mailto:<email address hidden>>
http://www.elico-corp.com

Elico Corp
On 06/18/2013 04:38 PM, Yannick Vaucher @ Camptocamp wrote:
> For the name_get function, it is a copy of official name_get but with few changes about constructing the name.
>
> The address concatenation where double \n are removed was taken from there. A cleanest way might be to ask for a hook to create the name.
>
> I also found the l.126-127 quite strange but I assume there are few chances that an address has more than 4 empty lines, even though it would be possible as there is no limit in country address format field.
>
> http://bazaar.launchpad.net/~openerp/openobject-server/7.0/view/head:/openerp/addons/base/res/res_partner.py#L524
>
> I'll check about Hidden category.

25. By Yannick Vaucher @ Camptocamp

[IMP] firstname_display_name_trigger - change category to Hidden

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

@Eric, sure it should be an improvement of partner_firstname module to choose which name is first. Module partner_firstname being a module to split the full name in 2 fields firstname, lastname.

And if partner_firstname module is improved that way, then we can update this module the same way.

By the way in partner_firstname and in this link module we are both computing the name to show lastname first and firstname second. After, as you have 2 separate names you can still use them how you want in your reports.

120 + name = '%s %s'%(record.lastname if record.lastname else u"",
121 + record.firstname if record.firstname else u"")

Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote :

Thanks for the change.
LGTM

review: Approve (code review, no test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Hello, could this one be merged please

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'firstname_display_name_trigger'
2=== added file 'firstname_display_name_trigger/__init__.py'
3--- firstname_display_name_trigger/__init__.py 1970-01-01 00:00:00 +0000
4+++ firstname_display_name_trigger/__init__.py 2013-06-18 08:49:26 +0000
5@@ -0,0 +1,24 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Author: Yannick Vaucher
10+# Copyright 2013 Camptocamp SA
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+
27+import res_partner
28+
29+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
30
31=== added file 'firstname_display_name_trigger/__openerp__.py'
32--- firstname_display_name_trigger/__openerp__.py 1970-01-01 00:00:00 +0000
33+++ firstname_display_name_trigger/__openerp__.py 2013-06-18 08:49:26 +0000
34@@ -0,0 +1,41 @@
35+# -*- coding: utf-8 -*-
36+##############################################################################
37+#
38+# Author: Yannick Vaucher
39+# Copyright 2013 Camptocamp SA
40+#
41+# This program is free software: you can redistribute it and/or modify
42+# it under the terms of the GNU Affero General Public License as
43+# published by the Free Software Foundation, either version 3 of the
44+# License, or (at your option) any later version.
45+#
46+# This program is distributed in the hope that it will be useful,
47+# but WITHOUT ANY WARRANTY; without even the implied warranty of
48+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49+# GNU Affero General Public License for more details.
50+#
51+# You should have received a copy of the GNU Affero General Public License
52+# along with this program. If not, see <http://www.gnu.org/licenses/>.
53+#
54+##############################################################################
55+{'name': 'Link module if partner_lastname and account_report_company are installed',
56+ 'version': '1.0',
57+ 'author': 'Camptocamp',
58+ 'maintainer': 'Camptocamp',
59+ 'category': 'Hidden',
60+ 'complexity': 'normal', # easy, normal, expert
61+ 'depends': [
62+ 'account_report_company',
63+ 'partner_firstname',
64+ ],
65+ 'description': """
66+Adapt the computation of display name so that it gets visible in tree and kanban views.
67+ """,
68+ 'website': 'http://www.camptocamp.com',
69+ 'data': [],
70+ 'installable': True,
71+ 'images': [],
72+ 'auto_install': True,
73+ 'license': 'AGPL-3',
74+ 'application': False}
75+
76
77=== added file 'firstname_display_name_trigger/res_partner.py'
78--- firstname_display_name_trigger/res_partner.py 1970-01-01 00:00:00 +0000
79+++ firstname_display_name_trigger/res_partner.py 2013-06-18 08:49:26 +0000
80@@ -0,0 +1,65 @@
81+# -*- coding: utf-8 -*-
82+##############################################################################
83+#
84+# Author: Yannick Vaucher
85+# Copyright 2013 Camptocamp SA
86+#
87+# This program is free software: you can redistribute it and/or modify
88+# it under the terms of the GNU Affero General Public License as
89+# published by the Free Software Foundation, either version 3 of the
90+# License, or (at your option) any later version.
91+#
92+# This program is distributed in the hope that it will be useful,
93+# but WITHOUT ANY WARRANTY; without even the implied warranty of
94+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
95+# GNU Affero General Public License for more details.
96+#
97+# You should have received a copy of the GNU Affero General Public License
98+# along with this program. If not, see <http://www.gnu.org/licenses/>.
99+#
100+##############################################################################
101+from openerp.osv import orm, fields
102+
103+
104+class ResPartner(orm.Model):
105+ _inherit = 'res.partner'
106+
107+ def _display_name_compute(self, cr, uid, ids, name, args, context=None):
108+ return dict(self.name_get(cr, uid, ids, context=context))
109+
110+ def name_get(self, cr, uid, ids, context=None):
111+ """ By pass of name_get to use directly firstname and lastname
112+ as we cannot ensure name as already been computed when calling this
113+ method for display_name"""
114+ if context is None:
115+ context = {}
116+ if isinstance(ids, (int, long)):
117+ ids = [ids]
118+ res = []
119+ for record in self.browse(cr, uid, ids, context=context):
120+ name = '%s %s'%(record.lastname if record.lastname else u"",
121+ record.firstname if record.firstname else u"")
122+ if record.parent_id and not record.is_company:
123+ name = "%s, %s" % (record.parent_id.name, name)
124+ if context.get('show_address'):
125+ name = name + "\n" + self._display_address(cr, uid, record, without_company=True, context=context)
126+ name = name.replace('\n\n','\n')
127+ name = name.replace('\n\n','\n')
128+ if context.get('show_email') and record.email:
129+ name = "%s <%s>" % (name, record.email)
130+ res.append((record.id, name))
131+ return res
132+
133+
134+ _display_name_store_triggers = {
135+ 'res.partner': (lambda self,cr,uid,ids,context=None: self.search(cr, uid, [('id','child_of',ids)]),
136+ ['parent_id', 'is_company', 'name', 'firstname', 'lastname'], 10)
137+ }
138+
139+ # indirection to avoid passing a copy of the overridable method when declaring the function field
140+ _display_name = lambda self, *args, **kwargs: self._display_name_compute(*args, **kwargs)
141+
142+ _columns = {
143+ # extra field to allow ORDER BY to match visible names
144+ 'display_name': fields.function(_display_name, type='char', string='Name', store=_display_name_store_triggers),
145+ }
146
147=== added directory 'firstname_display_name_trigger/tests'
148=== added file 'firstname_display_name_trigger/tests/__init__.py'
149--- firstname_display_name_trigger/tests/__init__.py 1970-01-01 00:00:00 +0000
150+++ firstname_display_name_trigger/tests/__init__.py 2013-06-18 08:49:26 +0000
151@@ -0,0 +1,5 @@
152+import test_display_name
153+
154+checks = [
155+ test_display_name
156+ ]
157
158=== added file 'firstname_display_name_trigger/tests/test_display_name.py'
159--- firstname_display_name_trigger/tests/test_display_name.py 1970-01-01 00:00:00 +0000
160+++ firstname_display_name_trigger/tests/test_display_name.py 2013-06-18 08:49:26 +0000
161@@ -0,0 +1,31 @@
162+import unittest2
163+
164+import openerp.tests.common as common
165+
166+class test_display_name(common.TransactionCase):
167+
168+ def setUp(self):
169+ super(test_display_name,self).setUp()
170+ cr, uid = self.cr, self.uid
171+ self.res_partner = self.registry('res.partner')
172+
173+
174+ def test_00_create_res_partner(self):
175+ """ Test if the display name has been correctly set """
176+ cr, uid = self.cr, self.uid
177+ partner_id = self.res_partner.create(cr, uid, {'lastname': 'Lastname', 'firstname': 'Firstname', 'is_company': True})
178+ partner_records = self.res_partner.browse(cr, uid, [partner_id])
179+ p1 = partner_records[0]
180+ self.assertEqual(p1.display_name, 'Lastname Firstname', 'Partner display_name incorect')
181+
182+ def test_01_res_partner_write_lastname(self):
183+ """ Test if the display name has been correctly set """
184+ cr, uid = self.cr, self.uid
185+ partner_id = self.res_partner.create(cr, uid, {'lastname': 'Lastname', 'firstname': 'Firstname', 'is_company': True})
186+ partner_records = self.res_partner.browse(cr, uid, [partner_id])
187+ p1 = partner_records[0]
188+ self.res_partner.write(cr, uid, partner_id, {'lastname': 'Last'})
189+ self.assertEqual(p1.display_name, 'Last Firstname', 'Partner display_name incorect')
190+
191+if __name__ == '__main__':
192+ unittest2.main()

Subscribers

People subscribed via source and target branches

to status/vote changes: