From 012122747d6a647b1c463d7201ccb24d19e8b6c1 Mon Sep 17 00:00:00 2001 From: Lorenzo Battistini Date: Wed, 22 Sep 2010 15:43:42 +0200 Subject: [PATCH 01/90] l10n_it: splittato in l10n_it_base, l10n_it_account e l10n_it_sale --- l10n_it_account/AUTHORS.txt | 9 +++ l10n_it_account/__init__.py | 25 ++++++++ l10n_it_account/__terp__.py | 38 +++++++++++++ l10n_it_account/account/__init__.py | 24 ++++++++ l10n_it_account/account/account.py | 72 ++++++++++++++++++++++++ l10n_it_account/account/invoice.py | 50 ++++++++++++++++ l10n_it_account/account/partner_view.xml | 15 +++++ l10n_it_account/i18n/it_IT.po | 51 +++++++++++++++++ l10n_it_account/i18n/l10n_it_account.pot | 50 ++++++++++++++++ 9 files changed, 334 insertions(+) create mode 100644 l10n_it_account/AUTHORS.txt create mode 100644 l10n_it_account/__init__.py create mode 100644 l10n_it_account/__terp__.py create mode 100644 l10n_it_account/account/__init__.py create mode 100644 l10n_it_account/account/account.py create mode 100644 l10n_it_account/account/invoice.py create mode 100644 l10n_it_account/account/partner_view.xml create mode 100644 l10n_it_account/i18n/it_IT.po create mode 100644 l10n_it_account/i18n/l10n_it_account.pot diff --git a/l10n_it_account/AUTHORS.txt b/l10n_it_account/AUTHORS.txt new file mode 100644 index 000000000000..4cedfa03425a --- /dev/null +++ b/l10n_it_account/AUTHORS.txt @@ -0,0 +1,9 @@ +Davide Corio +Luca Subiaco +Simone Orsi +Mario Riva +Mauro Soligo +Giovanni Barzan +Lorenzo Battistini +Roberto Onnis + diff --git a/l10n_it_account/__init__.py b/l10n_it_account/__init__.py new file mode 100644 index 000000000000..a566b33e67d1 --- /dev/null +++ b/l10n_it_account/__init__.py @@ -0,0 +1,25 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2010 OpenERP Italian Community (). +# All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import account +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/l10n_it_account/__terp__.py b/l10n_it_account/__terp__.py new file mode 100644 index 000000000000..ac192d5e1e9b --- /dev/null +++ b/l10n_it_account/__terp__.py @@ -0,0 +1,38 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2010 OpenERP Italian Community (). +# All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## +{ + 'name': 'Italian Localisation - Account', + 'version': '0.1', + 'category': 'Localisation/Italy', + 'description': """This module customizes OpenERP in order to fit italian laws and mores\nAccount version""", + 'author': 'OpenERP Italian Community', + 'website': 'http://www.openerp-italia.org', + 'license': 'AGPL-3', + "depends" : ['l10n_it_base','account','base_vat','account_chart','base_iban'], + "init_xml" : ['account/partner_view.xml'], + "update_xml" : [], + "demo_xml" : [], + "active": False, + "installable": True +} +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: + diff --git a/l10n_it_account/account/__init__.py b/l10n_it_account/account/__init__.py new file mode 100644 index 000000000000..b364a96db10d --- /dev/null +++ b/l10n_it_account/account/__init__.py @@ -0,0 +1,24 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2010 OpenERP Italian Community (). +# All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import account +import invoice diff --git a/l10n_it_account/account/account.py b/l10n_it_account/account/account.py new file mode 100644 index 000000000000..84e60439bf62 --- /dev/null +++ b/l10n_it_account/account/account.py @@ -0,0 +1,72 @@ +from osv import fields, osv + +class account_account_template(osv.osv): + _inherit = "account.account.template" + _columns = { + 'child_consol_ids': fields.many2many('account.account.template', 'account_account_template_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'), + } +account_account_template() + +''' + +#####funzionalita' compatibile solo con openERP V6##### + +class wizard_multi_charts_accounts(osv.osv_memory): + _inherit = 'wizard.multi.charts.accounts' + _defaults = { + 'code_digits': lambda *a:0, + } + def execute(self, cr, uid, ids, context=None): + super(wizard_multi_charts_accounts, self).execute(cr, uid, ids, context=None) + + obj_multi = self.browse(cr, uid, ids[0]) + obj_acc = self.pool.get('account.account') + obj_acc_template = self.pool.get('account.account.template') + obj_acc_root = obj_multi.chart_template_id.account_root_id + children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id]),('nocreate','!=',True)]) + children_acc_template.sort() + #scrivo i consolidati in account.account prendendoli da account.template + for account_template in obj_acc_template.browse(cr, uid, children_acc_template): + if(account_template.child_consol_ids): + dig = obj_multi.code_digits + code_main = account_template.code and len(account_template.code) or 0 + code_acc = account_template.code or '' + if code_main>0 and code_main<=dig and account_template.type != 'view': + code_acc=str(code_acc) + (str('0'*(dig-code_main))) + account_id = obj_acc.search(cr, uid, [('code','=',code_acc)]) + child_consol_ids = [] + for child in account_template.child_consol_ids: + child_consol_ids.append(child.id) + obj_acc.write(cr, uid, account_id, {'child_consol_ids': [(6, 0, child_consol_ids)]}) + +wizard_multi_charts_accounts() +''' + +class res_partner(osv.osv): + _inherit = 'res.partner' + + def check_fiscalcode(self, cr, uid, ids, context={}): + + for partner in self.browse(cr, uid, ids): + if not partner.fiscalcode: + return True + if len(partner.fiscalcode) != 16: + return False + + return True + + _columns = { + 'fiscalcode': fields.char('Fiscal Code', size=16, help="Italian Fiscal Code"), + } + #_constraints = [(check_fiscalcode, "The fiscal code doesn't seem to be correct.", ["fiscalcode"])] + + def check_fiscalcode(self, fiscalcode): + import re + pattern = r'^[A-Za-z]{6}[0-9]{2}[A-Za-z]{1}[0-9]{2}[A-Za-z]{1}[0-9]{3}[A-Za-z]{1}$' + #if len(fiscalcode) == 16 and re.findall(regexp,fiscalcode): + #if len(fiscalcode) == 16: + return True + #else: + # return False + +res_partner() diff --git a/l10n_it_account/account/invoice.py b/l10n_it_account/account/invoice.py new file mode 100644 index 000000000000..fa009167d0b5 --- /dev/null +++ b/l10n_it_account/account/invoice.py @@ -0,0 +1,50 @@ +# -*- encoding: utf-8 -*- +############################################################################## +# +# Copyright (C) 2010 OpenERP Italian Community (). +# All Rights Reserved +# $Id$ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +############################################################################## + +import netsvc +import pooler, tools + +from osv import fields, osv +from tools.translate import _ + +class Invoice(osv.osv): + + _inherit = 'account.invoice' + + def action_number(self, cr, uid, ids, *args): + super(Invoice, self).action_number(cr, uid, ids, args) + for obj_inv in self.browse(cr, uid, ids): + type = obj_inv.type + number = obj_inv.number + date_invoice = obj_inv.date_invoice + cr.execute("SELECT number FROM account_invoice i WHERE i.type = %s AND i.date_invoice > %s AND i.number < %s", (type, date_invoice, number)) + res = cr.dictfetchall() + if res: + raise osv.except_osv(_('Date Inconsistency'), + _('Cannot create invoice! Post the invoice with a greater date')) + return True + +Invoice() + + + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/l10n_it_account/account/partner_view.xml b/l10n_it_account/account/partner_view.xml new file mode 100644 index 000000000000..b4c0a78efd68 --- /dev/null +++ b/l10n_it_account/account/partner_view.xml @@ -0,0 +1,15 @@ + + + + + res.partner.fiscalcode.inherit + res.partner + + + + + + + + + diff --git a/l10n_it_account/i18n/it_IT.po b/l10n_it_account/i18n/it_IT.po new file mode 100644 index 000000000000..33c939791c74 --- /dev/null +++ b/l10n_it_account/i18n/it_IT.po @@ -0,0 +1,51 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * l10n_it_account +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 5.0.11\n" +"Report-Msgid-Bugs-To: support@openerp.com\n" +"POT-Creation-Date: 2010-09-22 13:09:25+0000\n" +"PO-Revision-Date: 2010-09-22 13:09:25+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: l10n_it_account +#: code:addons/l10n_it_account/account/invoice.py:0 +#, python-format +msgid "Cannot create invoice! Post the invoice with a greater date" +msgstr "Impossibile registrare la fattura in contabilità! Esistono fatture registrate con data successiva alla fattura corrente; inserisci una data superiore per il documento" + +#. module: l10n_it_account +#: constraint:ir.ui.view:0 +msgid "Invalid XML for View Architecture!" +msgstr "XML non valido per Visualizzazione Architettura!" + +#. module: l10n_it_account +#: field:account.account.template,child_consol_ids:0 +msgid "Consolidated Children" +msgstr "Conti consolidati" + +#. module: l10n_it_account +#: model:ir.module.module,description:l10n_it_account.module_meta_information +msgid "This module customizes OpenERP in order to fit italian laws and mores\n" +"Account version" +msgstr "Questo modulo personalizza OpenERP al fine di rispettare le leggi e le usanze italiane\n" +"Versione contabilità" + +#. module: l10n_it_account +#: code:addons/l10n_it_account/account/invoice.py:0 +#, python-format +msgid "Date Inconsistency" +msgstr "Inconsistenza nelle date" + +#. module: l10n_it_account +#: model:ir.module.module,shortdesc:l10n_it_account.module_meta_information +msgid "Italian Localisation - Account" +msgstr "Localizzazione Italiana - Contabilità" + diff --git a/l10n_it_account/i18n/l10n_it_account.pot b/l10n_it_account/i18n/l10n_it_account.pot new file mode 100644 index 000000000000..29c7a330fcb3 --- /dev/null +++ b/l10n_it_account/i18n/l10n_it_account.pot @@ -0,0 +1,50 @@ +# Translation of OpenERP Server. +# This file contains the translation of the following modules: +# * l10n_it_account +# +msgid "" +msgstr "" +"Project-Id-Version: OpenERP Server 5.0.11\n" +"Report-Msgid-Bugs-To: support@openerp.com\n" +"POT-Creation-Date: 2010-09-22 13:09:07+0000\n" +"PO-Revision-Date: 2010-09-22 13:09:07+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: l10n_it_account +#: code:addons/l10n_it_account/account/invoice.py:0 +#, python-format +msgid "Cannot create invoice! Post the invoice with a greater date" +msgstr "" + +#. module: l10n_it_account +#: constraint:ir.ui.view:0 +msgid "Invalid XML for View Architecture!" +msgstr "" + +#. module: l10n_it_account +#: field:account.account.template,child_consol_ids:0 +msgid "Consolidated Children" +msgstr "" + +#. module: l10n_it_account +#: model:ir.module.module,description:l10n_it_account.module_meta_information +msgid "This module customizes OpenERP in order to fit italian laws and mores\n" +"Account version" +msgstr "" + +#. module: l10n_it_account +#: code:addons/l10n_it_account/account/invoice.py:0 +#, python-format +msgid "Date Inconsistency" +msgstr "" + +#. module: l10n_it_account +#: model:ir.module.module,shortdesc:l10n_it_account.module_meta_information +msgid "Italian Localisation - Account" +msgstr "" + From 176db6c7861ffb4a8780b6600bcf60f04b4da4a6 Mon Sep 17 00:00:00 2001 From: Davide Corio Date: Tue, 28 Sep 2010 14:13:34 +0200 Subject: [PATCH 02/90] [IMP] added sale order -> invoice cross-reference (useful to access shipping data from the invoice -> "fattura accompagnatoria") MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit removed sale addon dependency from l10n_it_account various changes...just for fun ADD funzionalità compatibili solo con la V6 --- l10n_it_account/account/account.py | 3 +-- l10n_it_account/account/invoice.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/l10n_it_account/account/account.py b/l10n_it_account/account/account.py index 84e60439bf62..d54907a9ee4f 100644 --- a/l10n_it_account/account/account.py +++ b/l10n_it_account/account/account.py @@ -7,7 +7,6 @@ class account_account_template(osv.osv): } account_account_template() -''' #####funzionalita' compatibile solo con openERP V6##### @@ -40,7 +39,7 @@ def execute(self, cr, uid, ids, context=None): obj_acc.write(cr, uid, account_id, {'child_consol_ids': [(6, 0, child_consol_ids)]}) wizard_multi_charts_accounts() -''' + class res_partner(osv.osv): _inherit = 'res.partner' diff --git a/l10n_it_account/account/invoice.py b/l10n_it_account/account/invoice.py index fa009167d0b5..2ba3dad334c0 100644 --- a/l10n_it_account/account/invoice.py +++ b/l10n_it_account/account/invoice.py @@ -29,7 +29,7 @@ class Invoice(osv.osv): _inherit = 'account.invoice' - + def action_number(self, cr, uid, ids, *args): super(Invoice, self).action_number(cr, uid, ids, args) for obj_inv in self.browse(cr, uid, ids): From a8d60d0dc6e2fffef2b2197a9f0fa6372c8d4749 Mon Sep 17 00:00:00 2001 From: eLBati Date: Sat, 23 Oct 2010 16:35:16 +0200 Subject: [PATCH 03/90] FIX doppio step del wizard produceva giornali doppi updating branch structure --- l10n_it_account/account/account.py | 66 +++++++++++++++++++----------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/l10n_it_account/account/account.py b/l10n_it_account/account/account.py index d54907a9ee4f..e332116bdacc 100644 --- a/l10n_it_account/account/account.py +++ b/l10n_it_account/account/account.py @@ -7,11 +7,11 @@ class account_account_template(osv.osv): } account_account_template() - -#####funzionalita' compatibile solo con openERP V6##### - class wizard_multi_charts_accounts(osv.osv_memory): _inherit = 'wizard.multi.charts.accounts' + _columns = { + 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True, readonly=True), + } _defaults = { 'code_digits': lambda *a:0, } @@ -21,22 +21,49 @@ def execute(self, cr, uid, ids, context=None): obj_multi = self.browse(cr, uid, ids[0]) obj_acc = self.pool.get('account.account') obj_acc_template = self.pool.get('account.account.template') - obj_acc_root = obj_multi.chart_template_id.account_root_id - children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[obj_acc_root.id]),('nocreate','!=',True)]) - children_acc_template.sort() - #scrivo i consolidati in account.account prendendoli da account.template - for account_template in obj_acc_template.browse(cr, uid, children_acc_template): - if(account_template.child_consol_ids): - dig = obj_multi.code_digits + obj_acc_chart = self.pool.get('account.chart.template') + company_id = obj_multi.company_id.id + acc_template_ref = {} + #cerco tutti gli account.chart.template diversi da quello creato dal wizard di default + chart_template_ids = obj_acc_chart.search(cr, uid, [('id', '!=', obj_multi.chart_template_id.id)]) + for chart_template_id in chart_template_ids: + #genero il pdc consolidato + chart_template = obj_acc_chart.browse(cr, uid, chart_template_id) + children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[chart_template.account_root_id.id]),('nocreate','!=',True)]) + children_acc_template.sort() + for account_template in obj_acc_template.browse(cr, uid, children_acc_template): + tax_ids = [] + for tax in account_template.tax_ids: + tax_ids.append(tax_template_ref[tax.id]) + dig = 0 code_main = account_template.code and len(account_template.code) or 0 code_acc = account_template.code or '' if code_main>0 and code_main<=dig and account_template.type != 'view': code_acc=str(code_acc) + (str('0'*(dig-code_main))) - account_id = obj_acc.search(cr, uid, [('code','=',code_acc)]) - child_consol_ids = [] - for child in account_template.child_consol_ids: - child_consol_ids.append(child.id) - obj_acc.write(cr, uid, account_id, {'child_consol_ids': [(6, 0, child_consol_ids)]}) + vals={ + 'name': (chart_template.account_root_id.id == account_template.id) and chart_template.name or account_template.name, + 'currency_id': account_template.currency_id and account_template.currency_id.id or False, + 'code': code_acc, + 'type': account_template.type, + 'user_type': account_template.user_type and account_template.user_type.id or False, + 'reconcile': account_template.reconcile, + 'shortcut': account_template.shortcut, + 'note': account_template.note, + 'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False, + 'tax_ids': [(6,0,tax_ids)], + 'company_id': company_id, + } + + if(account_template.child_consol_ids): + #scrivo i consolidati in account.account prendendoli da account.template + account_id = obj_acc.search(cr, uid, [('code','=',code_acc)]) + child_consol_ids = [] + for child in account_template.child_consol_ids: + child_consol_ids.append(child.id) + vals['child_consol_ids'] = [(6, 0, child_consol_ids)] + + new_account = obj_acc.create(cr, uid, vals) + acc_template_ref[account_template.id] = new_account wizard_multi_charts_accounts() @@ -59,13 +86,4 @@ def check_fiscalcode(self, cr, uid, ids, context={}): } #_constraints = [(check_fiscalcode, "The fiscal code doesn't seem to be correct.", ["fiscalcode"])] - def check_fiscalcode(self, fiscalcode): - import re - pattern = r'^[A-Za-z]{6}[0-9]{2}[A-Za-z]{1}[0-9]{2}[A-Za-z]{1}[0-9]{3}[A-Za-z]{1}$' - #if len(fiscalcode) == 16 and re.findall(regexp,fiscalcode): - #if len(fiscalcode) == 16: - return True - #else: - # return False - res_partner() From 5f030b9048241d24064ebf1dbd4ae30cae85dff9 Mon Sep 17 00:00:00 2001 From: Davide Corio Date: Mon, 25 Oct 2010 15:43:38 +0200 Subject: [PATCH 04/90] [IMP] openerp v6 compatibility improvements [FIX] fixed compat issues --- l10n_it_account/{__terp__.py => __openerp__.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename l10n_it_account/{__terp__.py => __openerp__.py} (100%) diff --git a/l10n_it_account/__terp__.py b/l10n_it_account/__openerp__.py similarity index 100% rename from l10n_it_account/__terp__.py rename to l10n_it_account/__openerp__.py From 72b67063785b7d1159b50f41c234d64a846998c2 Mon Sep 17 00:00:00 2001 From: eLBati Date: Mon, 25 Oct 2010 16:28:19 +0200 Subject: [PATCH 05/90] ADD relation region -> country l10n_it_account: FIX translations l10n_it_account: FIX translations l10n_it_account: ADD fiscal code computation l10n_it_account: FIX error validating invoice l10n_it: FIX naming and removing dependency from other modules ADD l10n_it_ri_ba --- l10n_it_account/__init__.py | 2 +- l10n_it_account/__openerp__.py | 2 +- l10n_it_account/account/account.py | 161 +++++++++++++---------- l10n_it_account/account/invoice.py | 8 +- l10n_it_account/account/partner_view.xml | 24 +++- l10n_it_account/i18n/it.po | 154 ++++++++++++++++++++++ l10n_it_account/i18n/it_IT.po | 51 ------- l10n_it_account/i18n/l10n_it_account.pot | 117 ++++++++++++++-- 8 files changed, 380 insertions(+), 139 deletions(-) create mode 100644 l10n_it_account/i18n/it.po delete mode 100644 l10n_it_account/i18n/it_IT.po diff --git a/l10n_it_account/__init__.py b/l10n_it_account/__init__.py index a566b33e67d1..01dbb3ad2d95 100644 --- a/l10n_it_account/__init__.py +++ b/l10n_it_account/__init__.py @@ -6,7 +6,7 @@ # $Id$ # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by +# 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. # diff --git a/l10n_it_account/__openerp__.py b/l10n_it_account/__openerp__.py index ac192d5e1e9b..7decf8481e60 100644 --- a/l10n_it_account/__openerp__.py +++ b/l10n_it_account/__openerp__.py @@ -6,7 +6,7 @@ # $Id$ # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by +# 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. # diff --git a/l10n_it_account/account/account.py b/l10n_it_account/account/account.py index e332116bdacc..820224de9012 100644 --- a/l10n_it_account/account/account.py +++ b/l10n_it_account/account/account.py @@ -1,72 +1,5 @@ from osv import fields, osv - -class account_account_template(osv.osv): - _inherit = "account.account.template" - _columns = { - 'child_consol_ids': fields.many2many('account.account.template', 'account_account_template_consol_rel', 'child_id', 'parent_id', 'Consolidated Children'), - } -account_account_template() - -class wizard_multi_charts_accounts(osv.osv_memory): - _inherit = 'wizard.multi.charts.accounts' - _columns = { - 'chart_template_id': fields.many2one('account.chart.template', 'Chart Template', required=True, readonly=True), - } - _defaults = { - 'code_digits': lambda *a:0, - } - def execute(self, cr, uid, ids, context=None): - super(wizard_multi_charts_accounts, self).execute(cr, uid, ids, context=None) - - obj_multi = self.browse(cr, uid, ids[0]) - obj_acc = self.pool.get('account.account') - obj_acc_template = self.pool.get('account.account.template') - obj_acc_chart = self.pool.get('account.chart.template') - company_id = obj_multi.company_id.id - acc_template_ref = {} - #cerco tutti gli account.chart.template diversi da quello creato dal wizard di default - chart_template_ids = obj_acc_chart.search(cr, uid, [('id', '!=', obj_multi.chart_template_id.id)]) - for chart_template_id in chart_template_ids: - #genero il pdc consolidato - chart_template = obj_acc_chart.browse(cr, uid, chart_template_id) - children_acc_template = obj_acc_template.search(cr, uid, [('parent_id','child_of',[chart_template.account_root_id.id]),('nocreate','!=',True)]) - children_acc_template.sort() - for account_template in obj_acc_template.browse(cr, uid, children_acc_template): - tax_ids = [] - for tax in account_template.tax_ids: - tax_ids.append(tax_template_ref[tax.id]) - dig = 0 - code_main = account_template.code and len(account_template.code) or 0 - code_acc = account_template.code or '' - if code_main>0 and code_main<=dig and account_template.type != 'view': - code_acc=str(code_acc) + (str('0'*(dig-code_main))) - vals={ - 'name': (chart_template.account_root_id.id == account_template.id) and chart_template.name or account_template.name, - 'currency_id': account_template.currency_id and account_template.currency_id.id or False, - 'code': code_acc, - 'type': account_template.type, - 'user_type': account_template.user_type and account_template.user_type.id or False, - 'reconcile': account_template.reconcile, - 'shortcut': account_template.shortcut, - 'note': account_template.note, - 'parent_id': account_template.parent_id and ((account_template.parent_id.id in acc_template_ref) and acc_template_ref[account_template.parent_id.id]) or False, - 'tax_ids': [(6,0,tax_ids)], - 'company_id': company_id, - } - - if(account_template.child_consol_ids): - #scrivo i consolidati in account.account prendendoli da account.template - account_id = obj_acc.search(cr, uid, [('code','=',code_acc)]) - child_consol_ids = [] - for child in account_template.child_consol_ids: - child_consol_ids.append(child.id) - vals['child_consol_ids'] = [(6, 0, child_consol_ids)] - - new_account = obj_acc.create(cr, uid, vals) - acc_template_ref[account_template.id] = new_account - -wizard_multi_charts_accounts() - +import datetime class res_partner(osv.osv): _inherit = 'res.partner' @@ -83,7 +16,99 @@ def check_fiscalcode(self, cr, uid, ids, context={}): _columns = { 'fiscalcode': fields.char('Fiscal Code', size=16, help="Italian Fiscal Code"), + 'fiscalcode_surname': fields.char('Surname', size=64), + 'fiscalcode_firstname': fields.char('First name', size=64), + 'birth_date': fields.date('Date of birth'), + 'birth_city': fields.many2one('res.city', 'City of birth'), + 'sex': fields.selection([ + ('M','Male'), + ('F', 'Female'), + ], "Sex"), } #_constraints = [(check_fiscalcode, "The fiscal code doesn't seem to be correct.", ["fiscalcode"])] + + + def _codicefiscale(self, cognome, nome, giornonascita, mesenascita, annonascita, + sesso, cittanascita): + + MESI = 'ABCDEHLMPRST' + CONSONANTI = 'BCDFGHJKLMNPQRSTVWXYZ' + VOCALI = 'AEIOU' + LETTERE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' + REGOLECONTROLLO = { + 'A':(0,1), 'B':(1,0), 'C':(2,5), 'D':(3,7), 'E':(4,9), + 'F':(5,13), 'G':(6,15), 'H':(7,17), 'I':(8,19), 'J':(9,21), + 'K':(10,2), 'L':(11,4), 'M':(12,18), 'N':(13,20), 'O':(14,11), + 'P':(15,3), 'Q':(16,6), 'R':(17,8), 'S':(18,12), 'T':(19,14), + 'U':(20,16), 'V':(21,10), 'W':(22,22), 'X':(23,25), 'Y':(24,24), + 'Z':(25,23), + '0':(0,1), '1':(1,0), '2':(2,5), '3':(3,7), '4':(4,9), + '5':(5,13), '6':(6,15), '7':(7,17), '8':(8,19), '9':(9,21) + } + ### + # Funzioni + ## + + def _surname(stringa): + """Ricava, da stringa, 3 lettere in base alla convenzione dei CF.""" + cons = [c for c in stringa if c in CONSONANTI] + voc = [c for c in stringa if c in VOCALI] + chars=cons+voc + if len(chars)<3: + chars+=['X', 'X'] + return chars[:3] + + def _name(stringa): + """Ricava, da stringa, 3 lettere in base alla convenzione dei CF.""" + cons = [c for c in stringa if c in CONSONANTI] + voc = [c for c in stringa if c in VOCALI] + if len(cons)>3: + cons = [cons[0]] +[cons[2]] + [cons[3]] + chars=cons+voc + if len(chars)<3: + chars+=['X', 'X'] + return chars[:3] + + def _datan(giorno, mese, anno, sesso): + """Restituisce il campo data del CF.""" + chars = (list(anno[-2:]) + [MESI[int(mese)-1]]) + gn=int(giorno) + if sesso=='F': + gn+=40 + chars += list("%02d" % gn) + return chars + + def _codicecontrollo(c): + """Restituisce il codice di controllo, l'ultimo carattere del CF.""" + sommone = 0 + for i, car in enumerate(c): + j = 1 - i % 2 + sommone += REGOLECONTROLLO[car][j] + resto = sommone % 26 + return [LETTERE[resto]] + + """Restituisce il CF costruito sulla base degli argomenti.""" + nome=nome.upper() + cognome=cognome.upper() + sesso=sesso.upper() + cittanascita = cittanascita.upper() + chars = (_surname(cognome) + + _name(nome) + + _datan(giornonascita, mesenascita, annonascita, sesso) + + list(cittanascita)) + chars += _codicecontrollo(chars) + return ''.join(chars) + + def compute_fiscal_code(self, cr, uid, ids, context): + partners = self.browse(cr, uid, ids, context) + for partner in partners: + if not partner.fiscalcode_surname or not partner.fiscalcode_firstname or not partner.birth_date or not partner.birth_city or not partner.sex: + raise osv.except_osv('Error', 'One or more fields are missing') + birth_date = datetime.datetime.strptime(partner.birth_date, "%Y-%m-%d") + CF = self._codicefiscale(partner.fiscalcode_surname, partner.fiscalcode_firstname, str(birth_date.day), + str(birth_date.month), str(birth_date.year), partner.sex, + partner.birth_city.cadaster_code) + self.write(cr, uid, partner.id, {'fiscalcode': CF}) + return True res_partner() diff --git a/l10n_it_account/account/invoice.py b/l10n_it_account/account/invoice.py index 2ba3dad334c0..fa42b9f9dee9 100644 --- a/l10n_it_account/account/invoice.py +++ b/l10n_it_account/account/invoice.py @@ -26,12 +26,12 @@ from osv import fields, osv from tools.translate import _ -class Invoice(osv.osv): +class account_invoice(osv.osv): _inherit = 'account.invoice' - def action_number(self, cr, uid, ids, *args): - super(Invoice, self).action_number(cr, uid, ids, args) + def action_number(self, cr, uid, ids, context=None): + super(account_invoice, self).action_number(cr, uid, ids, context) for obj_inv in self.browse(cr, uid, ids): type = obj_inv.type number = obj_inv.number @@ -43,7 +43,7 @@ def action_number(self, cr, uid, ids, *args): _('Cannot create invoice! Post the invoice with a greater date')) return True -Invoice() +account_invoice() diff --git a/l10n_it_account/account/partner_view.xml b/l10n_it_account/account/partner_view.xml index b4c0a78efd68..d6f4e544b60d 100644 --- a/l10n_it_account/account/partner_view.xml +++ b/l10n_it_account/account/partner_view.xml @@ -1,14 +1,26 @@ - - res.partner.fiscalcode.inherit + + + res.partner.fiscalcode.data res.partner - + - - - + + + + + + + + + + + +