From 5acb91e36a5adf8353772f009155d208b2ea1d3a Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Mon, 13 Mar 2023 17:06:04 -0300 Subject: [PATCH 1/2] [FIX] purchase_ux: compute tax_ids if fiscal_position is setted on invoice Ticket: 59979 --- purchase_ux/models/purchase_order_line.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/purchase_ux/models/purchase_order_line.py b/purchase_ux/models/purchase_order_line.py index f2aab3c5..567ffe80 100644 --- a/purchase_ux/models/purchase_order_line.py +++ b/purchase_ux/models/purchase_order_line.py @@ -162,6 +162,23 @@ def _compute_invoice_qty(self): lines = AccountInvoiceLine.search([ ('move_id', '=', invoice_id), ('purchase_line_id', '=', rec.id)]) + for line in lines: + fp = line.move_id.fiscal_position_id + if fp: + product = line.with_context(force_company=self.company_id.id).product_id + account = line._get_computed_account() + if self.move_id.type not in ("out_invoice", "out_refund"): + taxes = product.supplier_taxes_id.filtered( + lambda tax: tax.company_id == self.company_id + ) + taxes = taxes or account.tax_ids.filtered( + lambda tax: tax.company_id == self.company_id + ) + taxes = fp.map_tax(taxes) + line.tax_ids = [(6, 0, taxes.ids)] + line._onchange_mark_recompute_taxes() + line.account_id = account.id + line.move_id.with_context(check_move_validity=False)._recompute_dynamic_lines() invoice_qty = -1.0 * sum( lines.mapped('quantity')) if AccountInvoice.browse( invoice_id).type == 'in_refund' else sum( From 22965e450467a8e3076f293bcc267e572ab08b0b Mon Sep 17 00:00:00 2001 From: Pablo Montenegro Date: Mon, 13 Mar 2023 17:12:58 -0300 Subject: [PATCH 2/2] [FIX] purchase_ux: otra manera de resolverlo --- purchase_ux/__manifest__.py | 3 ++- purchase_ux/models/purchase_order_line.py | 17 +---------------- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/purchase_ux/__manifest__.py b/purchase_ux/__manifest__.py index 5668658a..315cb48e 100644 --- a/purchase_ux/__manifest__.py +++ b/purchase_ux/__manifest__.py @@ -19,7 +19,7 @@ ############################################################################## { 'name': 'Purchase UX', - 'version': "13.0.1.3.0", + 'version': "13.0.1.4.0", 'category': 'Purchases', 'sequence': 14, 'summary': '', @@ -31,6 +31,7 @@ 'depends': [ 'purchase', 'account_ux', + 'account_fiscal_position_update', ], 'data': [ 'wizards/purchase_change_currency_views.xml', diff --git a/purchase_ux/models/purchase_order_line.py b/purchase_ux/models/purchase_order_line.py index 567ffe80..6e472139 100644 --- a/purchase_ux/models/purchase_order_line.py +++ b/purchase_ux/models/purchase_order_line.py @@ -163,22 +163,7 @@ def _compute_invoice_qty(self): ('move_id', '=', invoice_id), ('purchase_line_id', '=', rec.id)]) for line in lines: - fp = line.move_id.fiscal_position_id - if fp: - product = line.with_context(force_company=self.company_id.id).product_id - account = line._get_computed_account() - if self.move_id.type not in ("out_invoice", "out_refund"): - taxes = product.supplier_taxes_id.filtered( - lambda tax: tax.company_id == self.company_id - ) - taxes = taxes or account.tax_ids.filtered( - lambda tax: tax.company_id == self.company_id - ) - taxes = fp.map_tax(taxes) - line.tax_ids = [(6, 0, taxes.ids)] - line._onchange_mark_recompute_taxes() - line.account_id = account.id - line.move_id.with_context(check_move_validity=False)._recompute_dynamic_lines() + line.move_id.fiscal_position_change() invoice_qty = -1.0 * sum( lines.mapped('quantity')) if AccountInvoice.browse( invoice_id).type == 'in_refund' else sum(