Merge lp:~numerigraphe-team/account-financial-tools/7.0-l10n_fr_siret-view+company into lp:~account-core-editors/account-financial-tools/7.0

Proposed by Lionel Sausin - Initiatives/Numérigraphe
Status: Merged
Merged at revision: 175
Proposed branch: lp:~numerigraphe-team/account-financial-tools/7.0-l10n_fr_siret-view+company
Merge into: lp:~account-core-editors/account-financial-tools/7.0
Diff against target: 283 lines (+121/-69)
5 files modified
l10n_fr_siret/__init__.py (+2/-4)
l10n_fr_siret/__openerp__.py (+23/-16)
l10n_fr_siret/company.py (+44/-0)
l10n_fr_siret/partner.py (+25/-27)
l10n_fr_siret/partner_view.xml (+27/-22)
To merge this branch: bzr merge lp:~numerigraphe-team/account-financial-tools/7.0-l10n_fr_siret-view+company
Reviewer Review Type Date Requested Status
Guewen Baconnier @ Camptocamp code review Approve
Loïc Bellier - Numérigraphe (community) code review Approve
Alexandre Fayolle - camptocamp code review, no test Approve
Review via email: mp+212920@code.launchpad.net

Description of the change

This branch improves the module l10n_fr_siret :
- the SIREN and BIC fields are only shown in edit mode[*]
- SIRET is displayed as SIREN+"*****" if a SIREN with no NIC is entered
- the SIRET field introduced by l10n_fr is replaced by a "related" field for consistency.

[*] In v8 and in patched versions of v7, the SIRET is also hidden in read-only mode for better user experience

To post a comment you must log in.
175. By Numérigraphe

[IMP] hide the siret in edit mode to replace it with the siren+nic. Works only with a patched web client - see lp:~numerigraphe-team/openerp-web/7.0-hide-oe_view_only

176. By Numérigraphe

[FIX] fix store function for company.

177. By Numérigraphe

[IMP] visual improvement: set the SIRET to SIREN+'*****' when the NIC is empty. Use the style from v8 to hide the SIRET in edit view, instead of our own custom style

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

LGTM

review: Approve (code review, no test)
Revision history for this message
Loïc Bellier - Numérigraphe (lb-b) :
review: Approve (code review)
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'l10n_fr_siret/__init__.py'
2--- l10n_fr_siret/__init__.py 2011-12-08 14:10:34 +0000
3+++ l10n_fr_siret/__init__.py 2014-03-27 10:07:26 +0000
4@@ -1,4 +1,4 @@
5-# -*- encoding: utf-8 -*-
6+# -*- coding: utf-8 -*-
7 ##############################################################################
8 #
9 # OpenERP, Open Source Management Solution
10@@ -20,6 +20,4 @@
11 ##############################################################################
12
13 import partner
14-
15-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
16-
17+import company
18
19=== modified file 'l10n_fr_siret/__openerp__.py'
20--- l10n_fr_siret/__openerp__.py 2013-02-26 16:15:55 +0000
21+++ l10n_fr_siret/__openerp__.py 2014-03-27 10:07:26 +0000
22@@ -1,4 +1,4 @@
23-# -*- encoding: utf-8 -*-
24+# -*- coding: utf-8 -*-
25 ##############################################################################
26 #
27 # OpenERP, Open Source Management Solution
28@@ -21,25 +21,32 @@
29
30 {
31 'name': 'French company identity numbers SIRET/SIREN/NIC',
32- 'version': '1.0',
33+ 'version': '1.1',
34 "category": 'Accounting',
35- 'description': """
36-This module lets users keep track of the companies' unique
37-identification numbers from the official SIRENE registry in France:
38-SIRET, SIREN and NIC. These numbers identify each company and their
39-subsidiaries, and are often required for administrative tasks.
40-
41-At the top of the Partner form, users will be able to enter the SIREN
42+ 'description': '''
43+This module add the French company identity numbers.
44+====================================================
45+
46+This can help any company doing business with French companies
47+by letting users track the partners' unique identification
48+numbers from the official SIRENE registry in France: SIRET, SIREN and NIC.
49+These numbers identify each company and their subsidiaries, and are
50+often required for administrative tasks.
51+
52+On the Partner form, users will be able to enter the SIREN
53 and NIC numbers, and the SIRET number will be calculated
54 automatically. The last digits of the SIREN and NIC are control keys:
55 OpenERP will check their validity when partners are recorded.
56-""",
57- 'author' : u'Numérigraphe SARL',
58- 'depends': ['account'],
59- 'data': ['partner_view.xml',
60- ],
61+
62+ATTENTION! this module replaces the fields on the Company form with the new
63+ones on the Partner form, but it will NOT copy the corresponding data: you
64+will have to enter them again.
65+''',
66+ 'author': u'Numérigraphe SARL',
67+ 'depends': ['account', 'l10n_fr'],
68+ 'data': [
69+ 'partner_view.xml',
70+ ],
71 'installable': True,
72 'active': False,
73 }
74-
75-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
76
77=== added file 'l10n_fr_siret/company.py'
78--- l10n_fr_siret/company.py 1970-01-01 00:00:00 +0000
79+++ l10n_fr_siret/company.py 2014-03-27 10:07:26 +0000
80@@ -0,0 +1,44 @@
81+# -*- coding: utf-8 -*-
82+##############################################################################
83+#
84+# OpenERP, Open Source Management Solution
85+# Copyright (C) 2011 Numérigraphe SARL.
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+
102+from openerp.osv import fields, orm
103+
104+
105+class res_company(orm.Model):
106+ """Replace the company's fields for SIRET/RC with the partner's"""
107+ _inherit = 'res.company'
108+
109+ def _get_partner_change(self, cr, uid, ids, context=None):
110+ return self.pool.get('res.partner').search(
111+ cr, uid, [('partner_id', 'in', ids)], context=context)
112+
113+ _columns = {
114+ 'siret': fields.related(
115+ 'partner_id', 'siret', type='char', store={
116+ 'res.partner': (_get_partner_change, ['siren', 'nic'], 20),
117+ 'res.company': (lambda self, cr, uid, ids, c={}:
118+ ids, ['partner_id'], 20), }),
119+ 'company_registry': fields.related(
120+ 'partner_id', 'company_registry', type='char', store={
121+ 'res.partner': (_get_partner_change, ['company_registry'], 20),
122+ 'res.company': (lambda self, cr, uid, ids, c={}:
123+ ids, ['partner_id'], 20), })
124+ }
125
126=== modified file 'l10n_fr_siret/partner.py'
127--- l10n_fr_siret/partner.py 2013-02-05 16:03:32 +0000
128+++ l10n_fr_siret/partner.py 2014-03-27 10:07:26 +0000
129@@ -1,4 +1,4 @@
130-# -*- encoding: utf-8 -*-
131+# -*- coding: utf-8 -*-
132 ##############################################################################
133 #
134 # OpenERP, Open Source Management Solution
135@@ -27,10 +27,13 @@
136 def _check_luhn(string):
137 """Luhn test to check control keys
138
139- Credits: http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Python
140+ Credits:
141+ http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Python
142 """
143 r = [int(ch) for ch in string][::-1]
144- return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0
145+ return (sum(r[0::2]) + sum(sum(divmod(d * 2, 10))
146+ for d in r[1::2])) % 10 == 0
147+
148
149 class Partner(orm.Model):
150 """Add the French official company identity numbers SIREN, NIC and SIRET"""
151@@ -38,29 +41,26 @@
152
153 def _get_siret(self, cr, uid, ids, field_name, arg, context=None):
154 """Concatenate the SIREN and NIC to form the SIRET"""
155- sirets = {}
156- for partner in self.browse(cr, uid, ids, context=context):
157- if partner.siren and partner.nic:
158- sirets[partner.id] = '%s%s' % (partner.siren, partner.nic)
159- else:
160- sirets[partner.id] = ''
161- return sirets
162+ return {partner.id: '%s%s' % (partner.siren, partner.nic or '*****')
163+ if partner.siren else ''
164+ for partner in self.browse(cr, uid, ids, context=context)}
165
166 def _check_siret(self, cr, uid, ids):
167 """Check the SIREN's and NIC's keys (last digits)"""
168 for partner in self.browse(cr, uid, ids, context=None):
169 if partner.nic:
170 # Check the NIC type and length
171- if not partner.nic.isdecimal() or len(partner.nic)!=5:
172+ if not partner.nic.isdecimal() or len(partner.nic) != 5:
173 return False
174 if partner.siren:
175 # Check the SIREN type, length and key
176 if (not partner.siren.isdecimal()
177- or len(partner.siren)!=9
178- or not _check_luhn(partner.siren) ):
179+ or len(partner.siren) != 9
180+ or not _check_luhn(partner.siren)):
181 return False
182 # Check the NIC key (you need both SIREN and NIC to check it)
183- if partner.nic and not _check_luhn(partner.siren + partner.nic):
184+ if partner.nic and not _check_luhn(partner.siren
185+ + partner.nic):
186 return False
187 return True
188
189@@ -74,26 +74,24 @@
190 "of this office in the company in France. It "
191 "makes the last 5 digits of the SIRET "
192 "number."),
193- 'siret': fields.function(_get_siret, type="char", string='SIRET',
194+ 'siret': fields.function(
195+ _get_siret, type="char", string='SIRET',
196 method=True, size=14,
197- store = {
198+ store={
199 'res.partner': [lambda self, cr, uid, ids, context=None: ids,
200- ['siren', 'nic'],
201- 10]},
202+ ['siren', 'nic'], 10]},
203 help="The SIRET number is the official identity number of this "
204 "company's office in France. It is composed of the 9 digits "
205 "of the SIREN number and the 5 digits of the NIC number, ie. "
206 "14 digits."),
207- 'company_registry': fields.char('Company Registry', size=64,
208- help="The name of official registry where this "
209- "company was declared."),
210+ 'company_registry': fields.char(
211+ 'Company Registry', size=64,
212+ help="The name of official registry where this "
213+ "company was declared."),
214 }
215
216 _constraints = [
217- (_check_siret,
218- "The SIREN or NIC number is incorrect.",
219- ["siren", "nic"]),
220+ (_check_siret,
221+ "The SIREN or NIC number is incorrect.",
222+ ["siren", "nic"]),
223 ]
224-
225-
226-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
227
228=== modified file 'l10n_fr_siret/partner_view.xml'
229--- l10n_fr_siret/partner_view.xml 2012-08-27 16:40:53 +0000
230+++ l10n_fr_siret/partner_view.xml 2014-03-27 10:07:26 +0000
231@@ -1,25 +1,30 @@
232 <?xml version="1.0" encoding="utf-8"?>
233 <openerp>
234- <data>
235- <!-- Add the SIREN, NIC and SIRET numbers -->
236- <record model="ir.ui.view" id="view_partner_add">
237- <field name="name">res.partner.form.siret</field>
238- <field name="model">res.partner</field>
239- <field name="inherit_id" ref="account.view_partner_property_form" />
240- <field name="arch" type="xml">
241- <page string="Accounting" position="inside">
242- <group>
243- <group>
244- <field name="siren" />
245- <field name="nic" />
246- <field name="siret" />
247- </group>
248- <group>
249- <field name="company_registry" />
250- </group>
251- </group>
252- </page>
253- </field>
254- </record>
255- </data>
256+ <data>
257+ <!-- Add the SIREN and RC -->
258+ <record model="ir.ui.view" id="view_partner_add">
259+ <field name="name">res.partner.form.siret</field>
260+ <field name="model">res.partner</field>
261+ <field name="inherit_id" ref="account.view_partner_property_form" />
262+ <field name="arch" type="xml">
263+ <page string="Accounting" position="inside">
264+ <group>
265+ <group col="4">
266+ <!-- oe_read_only hides the field in read mode
267+ in v8+. v7.0 shows the field - no big deal.
268+ Those who care can patch the web client:
269+ lp:~numerigraphe-team/ocb-web/7.0-hide-oe_read_only
270+ -->
271+ <field name="siret" colspan="4" class="oe_read_only" />
272+ <field name="siren" class="oe_edit_only" string="SIREN/NIC" colspan="3"/>
273+ <field name="nic" class="oe_edit_only" nolabel="1"/>
274+ </group>
275+ <group>
276+ <field name="company_registry" />
277+ </group>
278+ </group>
279+ </page>
280+ </field>
281+ </record>
282+ </data>
283 </openerp>

Subscribers

People subscribed via source and target branches