diff --git a/l10n_pt_account_invoicexpress/models/account_move.py b/l10n_pt_account_invoicexpress/models/account_move.py index df4ba1bd..e8124986 100644 --- a/l10n_pt_account_invoicexpress/models/account_move.py +++ b/l10n_pt_account_invoicexpress/models/account_move.py @@ -76,6 +76,13 @@ def _compute_invoicexpress_doc_type(self): " If unset, InvoiceXpress will not be used.", ) + def _compute_is_l10npt_vat_enabled(self): + super()._compute_is_l10npt_vat_enabled() + # Disable VAT PT options is InvoiceXpress is disabled + for invoice in self.filtered("invoice.is_l10npt_vat_enabled"): + if not invoice.can_invoicexpress: + invoice.is_l10npt_vat_enabled = False + @api.constrains("journal_id", "company_id") def _check_invoicexpress_doctype_config(self): """ diff --git a/l10n_pt_vat/models/account_move.py b/l10n_pt_vat/models/account_move.py index beba7f1d..c7fdaaf0 100644 --- a/l10n_pt_vat/models/account_move.py +++ b/l10n_pt_vat/models/account_move.py @@ -8,6 +8,7 @@ class AccountMove(models.Model): _inherit = "account.move" + is_l10npt_vat_enabled = fields.Boolean(compute="_compute_is_l10npt_vat_enabled") vat_adjustment_norm_id = fields.Many2one( "account.vat.adjustment_norm", string="VAT Adjustment Norm", @@ -25,6 +26,12 @@ class AccountMove(models.Model): readonly=False, ) + def _compute_is_l10npt_vat_enabled(self): + for invoice in self: + invoice.is_l10npt_vat_enabled = ( + invoice.country_code == "PT" and invoice.is_sale_document() + ) + @api.depends("country_code", "move_type", "invoice_line_ids") def _compute_l10npt_has_tax_exempt_lines(self): for invoice in self: @@ -53,9 +60,7 @@ def action_post(self): """ VAT Exemption reason is required if there are lines without tax """ - for invoice in self.filtered( - lambda x: x.country_code == "PT" and x.is_sale_document() - ): + for invoice in self.filtered("is_l10npt_vat_enabled"): exempt_lines = invoice.invoice_line_ids.filtered( lambda x: not x.tax_ids.filtered("amount") ) diff --git a/l10n_pt_vat/views/account_move_view.xml b/l10n_pt_vat/views/account_move_view.xml index ddc33dd8..8928f3fe 100644 --- a/l10n_pt_vat/views/account_move_view.xml +++ b/l10n_pt_vat/views/account_move_view.xml @@ -8,16 +8,17 @@ - +
+ + -