diff --git a/account_invoice_en16931/models/account_move.py b/account_invoice_en16931/models/account_move.py index c3991fa..7d457ca 100644 --- a/account_invoice_en16931/models/account_move.py +++ b/account_invoice_en16931/models/account_move.py @@ -226,7 +226,8 @@ def _check_invoice_type_code(self): def _post(self, soft=True): for move in self.filtered(lambda x: x.is_sale_document()): - move.company_id._en16931_checks() + if move.company_id.en16931_issuer: + move.company_id._en16931_checks() errors = [] if not move.company_id.no_vat_taxes: for line in move.invoice_line_ids.filtered( diff --git a/account_invoice_en16931/models/res_company.py b/account_invoice_en16931/models/res_company.py index 526c591..aaea692 100644 --- a/account_invoice_en16931/models/res_company.py +++ b/account_invoice_en16931/models/res_company.py @@ -19,6 +19,14 @@ class ResCompany(models.Model): default="facturx", string="Default PDF Invoice Generation", ) + en16931_issuer = fields.Boolean( + string="Issues EN16931 e-Invoices", + help="Check the EN16931 configuration of this company when a customer " + "invoice is posted. Leave unchecked for companies that never emit an " + "EN16931 document: their tax configuration is then only checked when " + "such a document is actually generated. Localisation modules may set " + "this field for the companies they cover.", + ) no_vat_taxes = fields.Boolean( compute="_compute_no_vat_taxes", string="Company has no VAT Taxes" ) diff --git a/account_invoice_en16931/wizards/res_config_settings.py b/account_invoice_en16931/wizards/res_config_settings.py index 8fe1726..70d2628 100644 --- a/account_invoice_en16931/wizards/res_config_settings.py +++ b/account_invoice_en16931/wizards/res_config_settings.py @@ -11,6 +11,7 @@ class ResConfigSettings(models.TransientModel): en16931_default_pdf_invoice = fields.Selection( related="company_id.en16931_default_pdf_invoice", readonly=False ) + en16931_issuer = fields.Boolean(related="company_id.en16931_issuer", readonly=False) no_vat_taxes = fields.Boolean(related="company_id.no_vat_taxes") no_vat_taxes_vatex_id = fields.Many2one( related="company_id.no_vat_taxes_vatex_id", readonly=False @@ -22,3 +23,23 @@ class ResConfigSettings(models.TransientModel): string="Raise Error if Saxon Validation Fails", config_parameter="en16931.saxon_validation_blocking", ) + + def button_en16931_checks(self): + """Run the EN16931 configuration checks of the current company on demand. + + _en16931_checks() raises a UserError listing what is wrong, so reaching + the end means the company is properly configured. + """ + self.ensure_one() + self.company_id._en16931_checks() + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "type": "success", + "message": self.env._( + "The EN16931 configuration of company %s is valid.", + self.company_id.display_name, + ), + }, + } diff --git a/account_invoice_en16931/wizards/res_config_settings_view.xml b/account_invoice_en16931/wizards/res_config_settings_view.xml index 2da34db..aff9e3d 100644 --- a/account_invoice_en16931/wizards/res_config_settings_view.xml +++ b/account_invoice_en16931/wizards/res_config_settings_view.xml @@ -14,6 +14,21 @@ + + +
+
+