From 9a8d1e65a1438deb90a936c717da20232e9b4dcb Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 26 Mar 2014 16:21:12 +0100 Subject: [PATCH 1/8] [REF] PEP8 + removed emacs comments --- l10n_fr_siret/__init__.py | 5 +---- l10n_fr_siret/__openerp__.py | 27 ++++++++++++----------- l10n_fr_siret/partner.py | 42 +++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 36 deletions(-) diff --git a/l10n_fr_siret/__init__.py b/l10n_fr_siret/__init__.py index f9ccadcb7..1211ac390 100644 --- a/l10n_fr_siret/__init__.py +++ b/l10n_fr_siret/__init__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution @@ -20,6 +20,3 @@ ############################################################################## import partner - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: - diff --git a/l10n_fr_siret/__openerp__.py b/l10n_fr_siret/__openerp__.py index 9a02a5e26..226e7f4bf 100644 --- a/l10n_fr_siret/__openerp__.py +++ b/l10n_fr_siret/__openerp__.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution @@ -23,23 +23,26 @@ 'name': 'French company identity numbers SIRET/SIREN/NIC', 'version': '1.0', "category": 'Accounting', - 'description': """ -This module lets users keep track of the companies' unique -identification numbers from the official SIRENE registry in France: -SIRET, SIREN and NIC. These numbers identify each company and their -subsidiaries, and are often required for administrative tasks. + 'description': ''' +This module add the French company identity numbers. +==================================================== + +This can help any company doing business with French companies +by letting users track the partners' unique identification +numbers from the official SIRENE registry in France: SIRET, SIREN and NIC. +These numbers identify each company and their subsidiaries, and are +often required for administrative tasks. At the top of the Partner form, users will be able to enter the SIREN and NIC numbers, and the SIRET number will be calculated automatically. The last digits of the SIREN and NIC are control keys: OpenERP will check their validity when partners are recorded. -""", - 'author' : u'Numérigraphe SARL', +''', + 'author': u'Numérigraphe SARL', 'depends': ['account'], - 'data': ['partner_view.xml', - ], + 'data': [ + 'partner_view.xml', + ], 'installable': True, 'active': False, } - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/l10n_fr_siret/partner.py b/l10n_fr_siret/partner.py index 4291c0665..3966d441c 100644 --- a/l10n_fr_siret/partner.py +++ b/l10n_fr_siret/partner.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution @@ -27,10 +27,13 @@ from openerp.osv import fields, orm def _check_luhn(string): """Luhn test to check control keys - Credits: http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Python + Credits: + http://rosettacode.org/wiki/Luhn_test_of_credit_card_numbers#Python """ r = [int(ch) for ch in string][::-1] - return (sum(r[0::2]) + sum(sum(divmod(d*2,10)) for d in r[1::2])) % 10 == 0 + return (sum(r[0::2]) + sum(sum(divmod(d * 2, 10)) + for d in r[1::2])) % 10 == 0 + class Partner(orm.Model): """Add the French official company identity numbers SIREN, NIC and SIRET""" @@ -51,16 +54,17 @@ class Partner(orm.Model): for partner in self.browse(cr, uid, ids, context=None): if partner.nic: # Check the NIC type and length - if not partner.nic.isdecimal() or len(partner.nic)!=5: + if not partner.nic.isdecimal() or len(partner.nic) != 5: return False if partner.siren: # Check the SIREN type, length and key if (not partner.siren.isdecimal() - or len(partner.siren)!=9 - or not _check_luhn(partner.siren) ): + or len(partner.siren) != 9 + or not _check_luhn(partner.siren)): return False # Check the NIC key (you need both SIREN and NIC to check it) - if partner.nic and not _check_luhn(partner.siren + partner.nic): + if partner.nic and not _check_luhn(partner.siren + + partner.nic): return False return True @@ -74,26 +78,24 @@ class Partner(orm.Model): "of this office in the company in France. It " "makes the last 5 digits of the SIRET " "number."), - 'siret': fields.function(_get_siret, type="char", string='SIRET', + 'siret': fields.function( + _get_siret, type="char", string='SIRET', method=True, size=14, - store = { + store={ 'res.partner': [lambda self, cr, uid, ids, context=None: ids, - ['siren', 'nic'], - 10]}, + ['siren', 'nic'], 10]}, help="The SIRET number is the official identity number of this " "company's office in France. It is composed of the 9 digits " "of the SIREN number and the 5 digits of the NIC number, ie. " "14 digits."), - 'company_registry': fields.char('Company Registry', size=64, - help="The name of official registry where this " - "company was declared."), + 'company_registry': fields.char( + 'Company Registry', size=64, + help="The name of official registry where this " + "company was declared."), } _constraints = [ - (_check_siret, - "The SIREN or NIC number is incorrect.", - ["siren", "nic"]), + (_check_siret, + "The SIREN or NIC number is incorrect.", + ["siren", "nic"]), ] - - -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From e5a16381f8856e258b64ac0bac0e01153ce058d7 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 26 Mar 2014 17:22:09 +0100 Subject: [PATCH 2/8] [IMP] replace the SIRET & RC fields on the Company model --- l10n_fr_siret/__init__.py | 1 + l10n_fr_siret/__openerp__.py | 8 ++++++-- l10n_fr_siret/company.py | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 l10n_fr_siret/company.py diff --git a/l10n_fr_siret/__init__.py b/l10n_fr_siret/__init__.py index 1211ac390..7c560ac5e 100644 --- a/l10n_fr_siret/__init__.py +++ b/l10n_fr_siret/__init__.py @@ -20,3 +20,4 @@ ############################################################################## import partner +import company diff --git a/l10n_fr_siret/__openerp__.py b/l10n_fr_siret/__openerp__.py index 226e7f4bf..623cb5022 100644 --- a/l10n_fr_siret/__openerp__.py +++ b/l10n_fr_siret/__openerp__.py @@ -33,13 +33,17 @@ numbers from the official SIRENE registry in France: SIRET, SIREN and NIC. These numbers identify each company and their subsidiaries, and are often required for administrative tasks. -At the top of the Partner form, users will be able to enter the SIREN +On the Partner form, users will be able to enter the SIREN and NIC numbers, and the SIRET number will be calculated automatically. The last digits of the SIREN and NIC are control keys: OpenERP will check their validity when partners are recorded. + +ATTENTION! this module replaces the fields on the Company form with the new +ones on the Partner form, but it will NOT copy the corresponding data: you +will have to enter them again. ''', 'author': u'Numérigraphe SARL', - 'depends': ['account'], + 'depends': ['account', 'l10n_fr'], 'data': [ 'partner_view.xml', ], diff --git a/l10n_fr_siret/company.py b/l10n_fr_siret/company.py new file mode 100644 index 000000000..ffbcbbd06 --- /dev/null +++ b/l10n_fr_siret/company.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2011 Numérigraphe SARL. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import fields, orm + + +class res_company(orm.Model): + """Replace the company's fields for SIRET/RC with the ones on the partner""" + _inherit = 'res.company' + + _columns = { + 'siret': fields.related('partner_id', 'siret', type='char'), + 'company_registry': fields.related('partner_id', 'company_registry', type='char'), + } From 4ffe34daae6a50d8f1969c018e6132603a125a7c Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 26 Mar 2014 19:22:30 +0100 Subject: [PATCH 3/8] [FIX] store the company's siret and RC in the database --- l10n_fr_siret/company.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/l10n_fr_siret/company.py b/l10n_fr_siret/company.py index ffbcbbd06..1837bb63b 100644 --- a/l10n_fr_siret/company.py +++ b/l10n_fr_siret/company.py @@ -25,8 +25,17 @@ from openerp.osv import fields, orm class res_company(orm.Model): """Replace the company's fields for SIRET/RC with the ones on the partner""" _inherit = 'res.company' + + def _get_partner_change(self, cr, uid, ids, context=None): + return self.pool.get('res.partner').search(cr, uid, [('partner_id', 'in', ids)], context=context) _columns = { - 'siret': fields.related('partner_id', 'siret', type='char'), - 'company_registry': fields.related('partner_id', 'company_registry', type='char'), + 'siret': fields.related( + 'partner_id', 'siret', type='char', store={ + 'product.product': (_get_partner_change, ['siren', 'nic'], 20), + 'res.company': (lambda self, cr, uid, ids, c={}: ids, ['partner_id'], 20), }), + 'company_registry': fields.related( + 'partner_id', 'company_registry', type='char', store={ + 'product.product': (_get_partner_change, ['company_registry'], 20), + 'res.company': (lambda self, cr, uid, ids, c={}: ids, ['partner_id'], 20), }) } From 52e765f7b94b4c3bb92857bb3a084885331c49d0 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 26 Mar 2014 19:22:57 +0100 Subject: [PATCH 4/8] [IMP] Only show the SIREN/NIC in edit mode --- l10n_fr_siret/partner_view.xml | 44 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/l10n_fr_siret/partner_view.xml b/l10n_fr_siret/partner_view.xml index a53deeeba..a3122ab4e 100644 --- a/l10n_fr_siret/partner_view.xml +++ b/l10n_fr_siret/partner_view.xml @@ -1,25 +1,25 @@ - - - - res.partner.form.siret - res.partner - - - - - - - - - - - - - - - - - + + + + res.partner.form.siret + res.partner + + + + + + + + + + + + + + + + + From f59fb39b47f9aaa918f4f3188213102cb74b47a9 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 26 Mar 2014 19:25:06 +0100 Subject: [PATCH 5/8] [REL] bump version number for l10n_fr_siret --- l10n_fr_siret/__openerp__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/l10n_fr_siret/__openerp__.py b/l10n_fr_siret/__openerp__.py index 623cb5022..e8f12b796 100644 --- a/l10n_fr_siret/__openerp__.py +++ b/l10n_fr_siret/__openerp__.py @@ -21,7 +21,7 @@ { 'name': 'French company identity numbers SIRET/SIREN/NIC', - 'version': '1.0', + 'version': '1.1', "category": 'Accounting', 'description': ''' This module add the French company identity numbers. From ce34f0963874fb2e42cdb568537ad406fcdac095 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Wed, 26 Mar 2014 23:00:27 +0100 Subject: [PATCH 6/8] [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 --- l10n_fr_siret/partner_view.xml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/l10n_fr_siret/partner_view.xml b/l10n_fr_siret/partner_view.xml index a3122ab4e..d95f2bc0a 100644 --- a/l10n_fr_siret/partner_view.xml +++ b/l10n_fr_siret/partner_view.xml @@ -10,8 +10,10 @@ - - + + + From cb0156b2ca954dbc7b127f802a84d96851d7fb6d Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Thu, 27 Mar 2014 10:59:12 +0100 Subject: [PATCH 7/8] [FIX] fix store function for company. --- l10n_fr_siret/company.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/l10n_fr_siret/company.py b/l10n_fr_siret/company.py index 1837bb63b..146ee5f43 100644 --- a/l10n_fr_siret/company.py +++ b/l10n_fr_siret/company.py @@ -23,19 +23,22 @@ from openerp.osv import fields, orm class res_company(orm.Model): - """Replace the company's fields for SIRET/RC with the ones on the partner""" + """Replace the company's fields for SIRET/RC with the partner's""" _inherit = 'res.company' - + def _get_partner_change(self, cr, uid, ids, context=None): - return self.pool.get('res.partner').search(cr, uid, [('partner_id', 'in', ids)], context=context) + return self.pool.get('res.partner').search( + cr, uid, [('partner_id', 'in', ids)], context=context) _columns = { 'siret': fields.related( 'partner_id', 'siret', type='char', store={ - 'product.product': (_get_partner_change, ['siren', 'nic'], 20), - 'res.company': (lambda self, cr, uid, ids, c={}: ids, ['partner_id'], 20), }), + 'res.partner': (_get_partner_change, ['siren', 'nic'], 20), + 'res.company': (lambda self, cr, uid, ids, c={}: + ids, ['partner_id'], 20), }), 'company_registry': fields.related( 'partner_id', 'company_registry', type='char', store={ - 'product.product': (_get_partner_change, ['company_registry'], 20), - 'res.company': (lambda self, cr, uid, ids, c={}: ids, ['partner_id'], 20), }) + 'res.partner': (_get_partner_change, ['company_registry'], 20), + 'res.company': (lambda self, cr, uid, ids, c={}: + ids, ['partner_id'], 20), }) } From 607be79004f704f2f2450578c99e12b2f976b8b0 Mon Sep 17 00:00:00 2001 From: Lionel Sausin Date: Thu, 27 Mar 2014 11:04:12 +0100 Subject: [PATCH 8/8] [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 --- l10n_fr_siret/partner.py | 10 +++------- l10n_fr_siret/partner_view.xml | 9 ++++++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/l10n_fr_siret/partner.py b/l10n_fr_siret/partner.py index 3966d441c..13aac7653 100644 --- a/l10n_fr_siret/partner.py +++ b/l10n_fr_siret/partner.py @@ -41,13 +41,9 @@ class Partner(orm.Model): def _get_siret(self, cr, uid, ids, field_name, arg, context=None): """Concatenate the SIREN and NIC to form the SIRET""" - sirets = {} - for partner in self.browse(cr, uid, ids, context=context): - if partner.siren and partner.nic: - sirets[partner.id] = '%s%s' % (partner.siren, partner.nic) - else: - sirets[partner.id] = '' - return sirets + return {partner.id: '%s%s' % (partner.siren, partner.nic or '*****') + if partner.siren else '' + for partner in self.browse(cr, uid, ids, context=context)} def _check_siret(self, cr, uid, ids): """Check the SIREN's and NIC's keys (last digits)""" diff --git a/l10n_fr_siret/partner_view.xml b/l10n_fr_siret/partner_view.xml index d95f2bc0a..b373bb2b2 100644 --- a/l10n_fr_siret/partner_view.xml +++ b/l10n_fr_siret/partner_view.xml @@ -10,9 +10,12 @@ - - + +