Merge lp:~initos.com/partner-contact-management/7.0 into lp:~partner-contact-core-editors/partner-contact-management/7.0

Proposed by Thomas Rehn
Status: Merged
Merged at revision: 30
Proposed branch: lp:~initos.com/partner-contact-management/7.0
Merge into: lp:~partner-contact-core-editors/partner-contact-management/7.0
Diff against target: 275 lines (+239/-0)
7 files modified
base_partner_sequence/__init__.py (+22/-0)
base_partner_sequence/__openerp__.py (+54/-0)
base_partner_sequence/i18n/base_partner_sequence.pot (+21/-0)
base_partner_sequence/i18n/de.po (+21/-0)
base_partner_sequence/partner.py (+80/-0)
base_partner_sequence/partner_sequence.xml (+21/-0)
base_partner_sequence/partner_view.xml (+20/-0)
To merge this branch: bzr merge lp:~initos.com/partner-contact-management/7.0
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Pedro Manuel Baeza code review and test Approve
Stefan Rijnhart (Opener) Approve
Review via email: mp+195066@code.launchpad.net

Description of the change

I migrated 'base_partner_sequence' from lp:openobject-addons/extra-trunk to OpenERP v7.0. This module seems to fit well with the focus of your branch.

To post a comment you must log in.
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Thomas, indeed, this is the correct repository!

But we are following some code conventions to increase code quality. Please see this draft document for an explanation of all of them:

http://pad.openerp.com/p/community-review

Basically: PEP8, orm instead osv, not class initialisation, etc.

Regards.

review: Needs Fixing (code review, no test)
29. By Thomas Rehn

improve adherance to coding conventions

Revision history for this message
Thomas Rehn (thomas-rehn) wrote :

Hi Pedro,

Thank you for your suggestions. I hope the new revision is more appropriate for merging.

Best,
 Thomas.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Thomas, thank you very much for the changes. You can also change on the manifest file (__openerp__.py) the word demo instead demo_xml, remove update_xml, and change 'data' instead 'init_xml'.

Functionally speaking, I see only one problem: when you duplicate a partner, the code is kept on both partners, so you must inherit copy method to fix this. This can be more or less (please check, because I haven't tested and write it very quickly):

    def copy(self, cr, uid, ids, default=None, context=None):
        if default is None:
            default = {}
        default['ref'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner', context=context)
        return super(res_partner, self).copy(cr, uid, ids, default, context=context)

Regards.

review: Needs Fixing (code review, no test)
30. By Thomas Rehn

update keys in __openerp__ dictionary

31. By Thomas Rehn

implement 'copy' method, fix translation

Revision history for this message
Thomas Rehn (thomas-rehn) wrote :

Thank you for your suggestions. I have now added a 'copy' method and cleaned up the __openerp__.py.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Thomas, sorry for bothering you again, but there is other things you can improve:

- On __init__.py, instead of "import partner", please put "from . import partner".
- On __openerp__.py, you put on description that the sequence is for customer, but the code what makes is assign a sequence to customers, suppliers, users, and any partner that don't have a parent_id assigned. You should do two things:
   a) change description to put that the sequence is assigned to customers and supppliers.
   b) change _needsRef code to restrict the result to only customers and suppliers.
- When you call _needsRef method, you can use keyword arguments for better coding practises:

self._needsRef(cr, uid, id, None, context)

change by

self._needsRef(cr, uid, id=id, context=context)

Thank you for your effort.

Regards.

review: Needs Fixing
32. By Thomas Rehn

change the scope of sequences to customers and suppliers

Revision history for this message
Thomas Rehn (thomas-rehn) wrote :

Thanks again for the hints. The new revision assigns codes to customers and suppliers only. I also clarified the documentation.

33. By Thomas Rehn

whitespace cleanup

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Thomas,

Thanks for all your effort. I'm going to approve the MP, but for the final merge, it would be welcome to refactorize the few lines that exceed the 79 cols limit for PEP8 compliance.

Regards.

review: Approve
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Hi Thomas, thanks!

l.176 The get() method of ir.sequence is deprecated. I think 'next_by_code' should be used instead.

l.58 You claim authorship of the module, but I think 'Tiny' was the author. Maybe share the credits like you share the copyright?

l.195 I'm wondering if the condition should be in line with commercial partnership, i.e. maybe partners should qualify if there is no parent, or if the partner has is_company set (instead of being a supplier or a customer). What do think, Thomas and Pedro?

review: Needs Fixing
Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Stefan, good catch with next_by_code! I forgot this new call.

About is_company flag, it's very common that someone create a customer or a supplier and don't check this flag, but for the system, it will behave the same way as if you have ticked it, so I vote for stay as is.

Regards.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

On 11/18/2013 11:26 PM, Pedro Manuel Baeza wrote:
> About is_company flag, it's very common that someone create a customer or a supplier and don't check this flag, but for the system, it will behave the same way as if you have ticked it, so I vote for stay as is.

Thank you for your response. I think if someone creates a customer
without checking the flag 'is_customer', it will usually be a partner
without a parent so it will get assigned a reference according to my
suggestion. So that should not be a problem.

Please be aware that new contacts on an existing partner are a
'customer' as per system default, and 'supplier' if their parent is a
supplier. And you cannot modify these default values in the simple
add-contact popup in the partner form, because this form does not show
the customer/supplier options. That means that at least every new
contact will get assigned a reference, which seems to defeat the purpose
of having the _needRef logic to me.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Hi, Stefan,

I think we are mixing 'is_company' and 'is_customer'/is_supplier meanings. The way it is now, one partner doesn't get sequence number if it's not a customer or a supplier and ** VERY IMPORTANT ** if the parent_id is not empty, so contacts are not assigned a reference for now.

One common scenario is to press on Create button from Customers list, fill data, but not check 'is_company' flag. In this scenario, partner must have a reference, but with your logic it never gets it.

Regards.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

On 11/19/2013 10:31 AM, Pedro Manuel Baeza wrote:
> I think we are mixing 'is_company' and 'is_customer'/is_supplier
> meanings.

Yes, apparently my use case is for commercial partners, and your use
case is for partners marked as customer/suppliers. I must admit that my
use case is probably incomplete without some additional customization,
such as adding 'ref' to the fields that are copied to the non-commercial
contacts (and making it readonly on these contacts). Maybe this scenario
could be implemented in a separate module. I'll leave this point for now
then.

> One common scenario is to press on Create button from Customers list,
> fill data, but not check 'is_company' flag. In this scenario, partner
> must have a reference, but with your logic it never gets it.
>

What I was suggesting was that that such a partner gets a reference as
long as you do not assign a parent company, as per my commercial partner
use case.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

> Yes, apparently my use case is for commercial partners, and your use
> case is for partners marked as customer/suppliers. I must admit that my
> use case is probably incomplete without some additional customization,
> such as adding 'ref' to the fields that are copied to the non-commercial
> contacts (and making it readonly on these contacts). Maybe this scenario
> could be implemented in a separate module. I'll leave this point for now
> then.

OK, I understand you, and yes, I think it's also important to get propagated the reference across children partners to mimic the current logic on partner structure. Maybe we should implement this together in this module to get a definitive module for v7.

> What I was suggesting was that that such a partner gets a reference as
> long as you do not assign a parent company, as per my commercial partner
> use case.

So you are proposing to remove is_customer/is_supplier check?

Regards.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Yes, I am suggesting to keep to the commercial partner concept from OpenERP 7.0 (commercial partners are partners without a parent, or partners with is_company set to true), instead of the customer/supplier criterium. While the latter makes sense conceptually, the defaults for these values in OpenERP render these criteria useless IMHO.

I'm tentatively proposing my suggestions into this branch here: https://code.launchpad.net/~therp-nl/partner-contact-management/7.0-base_partner_sequence_commercial_partner/+merge/195742

Sorry Thomas if you feel I am trying to get in the way. Consider it an illustration of the discussion. Feel free to comment.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

I have approved the MP to this branch because I see the changes very correct. Thanks for proposing them.

Thomas, please take in consideration this proposition.

Regards.

Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

Thanks for reviewing and taking my suggestions!

review: Approve
35. By Thomas Rehn

shortened long lines

Revision history for this message
Thomas Rehn (thomas-rehn) wrote :

I have finally managed to shorten the lines so that the code now is PEP-8 compliant.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Thanks for the PEP8! Checking again the code for the final inclusion, I have seen another potential problem: on the line 'if not default.get('ref')...' from the copy, this means that if the original record hasn't got ref, it is assigned a new one, but what we have to do is always assign a new sequence if requirements are met, independently from the old value.

Can you check it, please?

Regards.

review: Needs Fixing
36. By Thomas Rehn

fix a bug in copying an object with a ref

Revision history for this message
Thomas Rehn (thomas-rehn) wrote :

Thanks for the hint, I address this issue in my last commit.

Revision history for this message
Pedro Manuel Baeza (pedro.baeza) wrote :

Thank you very much for all your effort.

Regards.

review: Approve (code review and test)
Revision history for this message
Holger Brunn (Therp) (hbrunn) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'base_partner_sequence'
2=== added file 'base_partner_sequence/__init__.py'
3--- base_partner_sequence/__init__.py 1970-01-01 00:00:00 +0000
4+++ base_partner_sequence/__init__.py 2013-12-02 16:16:05 +0000
5@@ -0,0 +1,22 @@
6+# -*- encoding: utf-8 -*-
7+##############################################################################
8+#
9+# OpenERP, Open Source Management Solution
10+# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
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+from . import partner
27+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
28
29=== added file 'base_partner_sequence/__openerp__.py'
30--- base_partner_sequence/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ base_partner_sequence/__openerp__.py 2013-12-02 16:16:05 +0000
32@@ -0,0 +1,54 @@
33+# -*- encoding: utf-8 -*-
34+##############################################################################
35+#
36+# OpenERP, Open Source Management Solution
37+# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
38+# Copyright (C) 2013 initOS GmbH & Co. KG (<http://www.initos.com>).
39+# Author Thomas Rehn <thomas.rehn at initos.com>
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+{
56+ "name": "Add a sequence on customers' code",
57+ "version": "1.1",
58+ "author": "Tiny/initOS GmbH & Co. KG",
59+ "category": "Generic Modules/Base",
60+ "website": "http://www.initos.com",
61+ "depends": ["base"],
62+ "summary": "Sets customer's code from a sequence",
63+ "description": """
64+ This module adds the possibility to define a sequence for
65+ the partner code. This code is then set as default when you
66+ create a new commercial partner, using the defined sequence.
67+
68+ The reference field is treated as a commercial field, i.e. it
69+ is managed from the commercial partner and then propagated to
70+ the partner's contacts. The field is visible on the contacts,
71+ but it can only be modified from the commercial partner.
72+
73+ No codes are assigned for contacts such as shipping and
74+ invoice addresses.
75+ This module is a migration of the original base_partner_sequence
76+ addon to OpenERP version 7.0.
77+ """,
78+ "data": [
79+ 'partner_sequence.xml',
80+ 'partner_view.xml',
81+ ],
82+ "demo": [],
83+ "active": False,
84+ "installable": True
85+}
86+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
87
88=== added directory 'base_partner_sequence/i18n'
89=== added file 'base_partner_sequence/i18n/base_partner_sequence.pot'
90--- base_partner_sequence/i18n/base_partner_sequence.pot 1970-01-01 00:00:00 +0000
91+++ base_partner_sequence/i18n/base_partner_sequence.pot 2013-12-02 16:16:05 +0000
92@@ -0,0 +1,21 @@
93+# Translation of OpenERP Server.
94+# This file contains the translation of the following modules:
95+#
96+msgid ""
97+msgstr ""
98+"Project-Id-Version: OpenERP Server 7.0-20131013-231025\n"
99+"Report-Msgid-Bugs-To: \n"
100+"POT-Creation-Date: 2013-11-13 13:47+0000\n"
101+"PO-Revision-Date: 2013-11-13 13:47+0000\n"
102+"Last-Translator: <>\n"
103+"Language-Team: \n"
104+"MIME-Version: 1.0\n"
105+"Content-Type: text/plain; charset=UTF-8\n"
106+"Content-Transfer-Encoding: \n"
107+"Plural-Forms: \n"
108+
109+#. module: base_partner_sequence
110+#: model:ir.model,name:base_partner_sequence.model_res_partner
111+msgid "Partner"
112+msgstr ""
113+
114
115=== added file 'base_partner_sequence/i18n/de.po'
116--- base_partner_sequence/i18n/de.po 1970-01-01 00:00:00 +0000
117+++ base_partner_sequence/i18n/de.po 2013-12-02 16:16:05 +0000
118@@ -0,0 +1,21 @@
119+# Translation of OpenERP Server.
120+# This file contains the translation of the following modules:
121+#
122+msgid ""
123+msgstr ""
124+"Project-Id-Version: OpenERP Server 7.0-20131013-231025\n"
125+"Report-Msgid-Bugs-To: \n"
126+"POT-Creation-Date: 2013-11-13 13:47+0000\n"
127+"PO-Revision-Date: 2013-11-13 13:47+0000\n"
128+"Last-Translator: <>\n"
129+"Language-Team: \n"
130+"MIME-Version: 1.0\n"
131+"Content-Type: text/plain; charset=UTF-8\n"
132+"Content-Transfer-Encoding: \n"
133+"Plural-Forms: \n"
134+
135+#. module: base_partner_sequence
136+#: model:ir.model,name:base_partner_sequence.model_res_partner
137+msgid "Partner"
138+msgstr "Partner"
139+
140
141=== added file 'base_partner_sequence/partner.py'
142--- base_partner_sequence/partner.py 1970-01-01 00:00:00 +0000
143+++ base_partner_sequence/partner.py 2013-12-02 16:16:05 +0000
144@@ -0,0 +1,80 @@
145+# -*- encoding: utf-8 -*-
146+##############################################################################
147+#
148+# OpenERP, Open Source Management Solution
149+# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
150+# Copyright (C) 2013 initOS GmbH & Co. KG (<http://www.initos.com>).
151+# Author Thomas Rehn <thomas.rehn at initos.com>
152+#
153+# This program is free software: you can redistribute it and/or modify
154+# it under the terms of the GNU Affero General Public License as
155+# published by the Free Software Foundation, either version 3 of the
156+# License, or (at your option) any later version.
157+#
158+# This program is distributed in the hope that it will be useful,
159+# but WITHOUT ANY WARRANTY; without even the implied warranty of
160+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
161+# GNU Affero General Public License for more details.
162+#
163+# You should have received a copy of the GNU Affero General Public License
164+# along with this program. If not, see <http://www.gnu.org/licenses/>.
165+#
166+##############################################################################
167+
168+from openerp.osv import orm, fields
169+
170+
171+class ResPartner(orm.Model):
172+ """Assigns 'ref' from a sequence on creation and copying"""
173+
174+ _inherit = 'res.partner'
175+
176+ def create(self, cr, uid, vals, context=None):
177+ context = context or {}
178+ if not vals.get('ref') and self._needsRef(cr, uid, vals=vals,
179+ context=context):
180+ vals['ref'] = self.pool.get('ir.sequence')\
181+ .next_by_code(cr, uid, 'res.partner')
182+ return super(ResPartner, self).create(cr, uid, vals, context)
183+
184+ def copy(self, cr, uid, id, default=None, context=None):
185+ default = default or {}
186+ if self._needsRef(cr, uid, id=id, context=context):
187+ default['ref'] = self.pool.get('ir.sequence')\
188+ .next_by_code(cr, uid, 'res.partner',
189+ context=context)
190+ return super(ResPartner, self).copy(cr, uid, id, default,
191+ context=context)
192+
193+ def _needsRef(self, cr, uid, id=None, vals=None, context=None):
194+ """
195+ Checks whether a sequence value should be assigned to a partner's 'ref'
196+
197+ :param cr: database cursor
198+ :param uid: current user id
199+ :param id: id of the partner object
200+ :param vals: known field values of the partner object
201+ :return: true iff a sequence value should be assigned to the\
202+ partner's 'ref'
203+ """
204+ if not vals and not id:
205+ raise Exception('Either field values or an id must be provided.')
206+ # only assign a 'ref' to commercial partners
207+ if id:
208+ vals = self.read(cr, uid, id, ['parent_id', 'is_company'],
209+ context=context)
210+ return vals.get('is_company') or not vals.get('parent_id')
211+
212+ _columns = {
213+ 'ref': fields.char('Reference', size=64, readonly=True),
214+ }
215+
216+ def _commercial_fields(self, cr, uid, context=None):
217+ """
218+ Make the partner reference a field that is propagated
219+ to the partner's contacts
220+ """
221+ return super(ResPartner, self)._commercial_fields(
222+ cr, uid, context=context) + ['ref']
223+
224+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
225
226=== added file 'base_partner_sequence/partner_sequence.xml'
227--- base_partner_sequence/partner_sequence.xml 1970-01-01 00:00:00 +0000
228+++ base_partner_sequence/partner_sequence.xml 2013-12-02 16:16:05 +0000
229@@ -0,0 +1,21 @@
230+<?xml version="1.0"?>
231+<openerp>
232+<data noupdate="1">
233+
234+ #
235+ # Sequences for res.partner
236+ #
237+
238+ <record model="ir.sequence.type" id="seq_type_res_partner">
239+ <field name="name">Partner code</field>
240+ <field name="code">res.partner</field>
241+ </record>
242+ <record model="ir.sequence" id="seq_res_partner">
243+ <field name="name">Partner code</field>
244+ <field name="code">res.partner</field>
245+ <field name="prefix">P/</field>
246+ <field name="padding">5</field>
247+ </record>
248+
249+</data>
250+</openerp>
251
252=== added file 'base_partner_sequence/partner_view.xml'
253--- base_partner_sequence/partner_view.xml 1970-01-01 00:00:00 +0000
254+++ base_partner_sequence/partner_view.xml 2013-12-02 16:16:05 +0000
255@@ -0,0 +1,20 @@
256+<?xml version="1.0" encoding="UTF-8"?>
257+<openerp>
258+ <data>
259+
260+ <record id="view_partner_form" model="ir.ui.view">
261+ <field name="name">Make partner reference readonly when non-commercial</field>
262+ <field name="model">res.partner</field>
263+ <field name="inherit_id" ref="base.view_partner_form"/>
264+ <field name="arch" type="xml">
265+ <field name="ref" position="attributes">
266+ <attribute name="attrs">{
267+ 'readonly': [('is_company', '=', False),
268+ ('parent_id', '!=', False)]}</attribute>
269+ </field>
270+ </field>
271+
272+ </record>
273+ </data>
274+</openerp>
275+