From 9f12a39396ae875d71d7e1dfa3d66152f34b02e3 Mon Sep 17 00:00:00 2001 From: Julien Van Roy Date: Tue, 11 Jan 2022 12:55:32 +0000 Subject: [PATCH] [FIX] l10n_fr_fec: prevent error for non-french vat As the FEC can be downloaded by non-french companies, the length of a given vat number might be different than the french's vat. Currently, if the vat length was lower than 13, it raised an error. For french companies -> include the SIREN in the name of the FEC file (legal requirement) For non french companies -> include the complete vat number in the FEC file closes odoo/odoo#83054 X-original-commit: c3c05bf073a521a662d83c3382e77cb25c59bc3c Signed-off-by: Laurent Smet --- addons/l10n_fr_fec/i18n/fr.po | 10 ++++++++++ addons/l10n_fr_fec/i18n/l10n_fr_fec.pot | 6 ++++++ addons/l10n_fr_fec/wizard/account_fr_fec.py | 20 ++++++++++++++++---- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/addons/l10n_fr_fec/i18n/fr.po b/addons/l10n_fr_fec/i18n/fr.po index 15de447e897..37fbaec2e5b 100644 --- a/addons/l10n_fr_fec/i18n/fr.po +++ b/addons/l10n_fr_fec/i18n/fr.po @@ -238,6 +238,16 @@ msgstr "" msgid "Non-official FEC report (posted and unposted entries)" msgstr "Rapport FEC non-officiel (avec à la fois les entrées comptabilisées et non comptabilisées)" +#: code:addons/l10n_fr_fec/wizard/fec.py:98 +#, python-format +msgid "Invalid VAT number for company %s" +msgstr "Numéro de TVA invalide sur la société %s" + +#. module: l10n_fr_fec +#: view:account.fr.fec:0 +msgid "Cancel" +msgstr "Annuler" + #. module: l10n_fr_fec #: model:ir.model.fields.selection,name:l10n_fr_fec.selection__account_fr_fec__export_type__official msgid "Official FEC report (posted entries only)" diff --git a/addons/l10n_fr_fec/i18n/l10n_fr_fec.pot b/addons/l10n_fr_fec/i18n/l10n_fr_fec.pot index b6044624519..aa525db8f2c 100644 --- a/addons/l10n_fr_fec/i18n/l10n_fr_fec.pot +++ b/addons/l10n_fr_fec/i18n/l10n_fr_fec.pot @@ -228,6 +228,12 @@ msgstr "" msgid "Missing VAT number for company %s" msgstr "" +#. module: l10n_fr_fec +#: code:addons/l10n_fr_fec/wizard/account_fr_fec.py:98 +#, python-format +msgid "Invalid VAT number for company %s" +msgstr "" + #. module: l10n_fr_fec #: model_terms:ir.ui.view,arch_db:l10n_fr_fec.account_fr_fec_view msgid "Montantdevise" diff --git a/addons/l10n_fr_fec/wizard/account_fr_fec.py b/addons/l10n_fr_fec/wizard/account_fr_fec.py index 3f61bdbb99f..a641d97692d 100644 --- a/addons/l10n_fr_fec/wizard/account_fr_fec.py +++ b/addons/l10n_fr_fec/wizard/account_fr_fec.py @@ -10,6 +10,7 @@ from odoo import api, fields, models, _ from odoo.exceptions import UserError, AccessDenied from odoo.tools import float_is_zero, pycompat from odoo.tools.misc import get_lang +from stdnum.fr import siren class AccountFrFec(models.TransientModel): @@ -89,13 +90,24 @@ class AccountFrFec(models.TransientModel): sources: https://www.service-public.fr/professionnels-entreprises/vosdroits/F23570 http://www.douane.gouv.fr/articles/a11024-tva-dans-les-dom + + * Returns the siren if the company is french or an empty siren for dom-tom + * For non-french companies -> returns the complete vat number """ dom_tom_group = self.env.ref('l10n_fr.dom-tom') is_dom_tom = company.account_fiscal_country_id.code in dom_tom_group.country_ids.mapped('code') - if not company.vat or is_dom_tom: - return {'siren': ''} + if is_dom_tom: + return '' + elif company.country_id.code == 'FR': + if not company.vat: + raise UserError(_("Missing VAT number for company %s") % company.display_name) + elif len(company.vat) < 13 or not siren.is_valid(company.vat[4:13]): + raise UserError(_("Invalid VAT number for company %s") % company.display_name) + else: + return company.vat[4:13] else: - return {'siren': company.vat[4:13]} + return '' if not company.vat else company.vat + def generate_fec(self): self.ensure_one() @@ -383,7 +395,7 @@ class AccountFrFec(models.TransientModel): self.write({ 'fec_data': base64.encodebytes(fecvalue), # Filename = FECYYYYMMDD where YYYMMDD is the closing date - 'filename': '%sFEC%s%s.csv' % (company_legal_data['siren'], end_date, suffix), + 'filename': '%sFEC%s%s.csv' % (company_legal_data, end_date, suffix), }) # Set fiscal year lock date to the end date (not in test)