From 9a80e2fa47433ff1a759d97ddc7243ec067574b8 Mon Sep 17 00:00:00 2001 From: oco-odoo Date: Mon, 25 Oct 2021 11:43:44 +0000 Subject: [PATCH] [FIX] purchase, sale: filter taxes properly when using a foreign VAT fiscal position Before, when a foreign VAT fiscal position was used on a purchase order or sale order, no filtering was applied on the available taxes. We now make their behavior consistent with the invoices'. Part-of: odoo/odoo#79144 --- addons/purchase/models/purchase.py | 12 ++++++++++++ addons/purchase/views/purchase_views.xml | 13 +++++++------ addons/sale/models/sale_order.py | 12 ++++++++++++ addons/sale/views/sale_views.xml | 5 +++-- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 4c6259b96d0..21f77feb870 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -122,6 +122,10 @@ class PurchaseOrder(models.Model): amount_total = fields.Monetary(string='Total', store=True, readonly=True, compute='_amount_all') fiscal_position_id = fields.Many2one('account.fiscal.position', string='Fiscal Position', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") + tax_country_id = fields.Many2one( + comodel_name='res.country', + compute='_compute_tax_country_id', + help="Technical field to filter the available taxes depending on the fiscal country and fiscal position.") payment_term_id = fields.Many2one('account.payment.term', 'Payment Terms', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") incoterm_id = fields.Many2one('account.incoterms', 'Incoterm', states={'done': [('readonly', True)]}, help="International Commercial Terms are a series of predefined commercial terms used in international transactions.") @@ -207,6 +211,14 @@ class PurchaseOrder(models.Model): tax_totals = account_move._get_tax_totals(order.partner_id, tax_lines_data, order.amount_total, order.amount_untaxed, order.currency_id) order.tax_totals_json = json.dumps(tax_totals) + @api.depends('company_id.account_fiscal_country_id', 'fiscal_position_id.country_id', 'fiscal_position_id.foreign_vat') + def _compute_tax_country_id(self): + for record in self: + if record.fiscal_position_id.foreign_vat: + record.tax_country_id = record.fiscal_position_id.country_id + else: + record.tax_country_id = record.company_id.account_fiscal_country_id + @api.onchange('date_planned') def onchange_date_planned(self): if self.date_planned: diff --git a/addons/purchase/views/purchase_views.xml b/addons/purchase/views/purchase_views.xml index 9c643b28c82..0eb5ad051cd 100644 --- a/addons/purchase/views/purchase_views.xml +++ b/addons/purchase/views/purchase_views.xml @@ -197,7 +197,7 @@ Ask confirmation
- day(s) before + day(s) before
@@ -205,6 +205,7 @@ + - +
@@ -273,7 +274,7 @@ - + @@ -533,7 +534,7 @@ - + @@ -541,8 +542,8 @@ purchase.order -