From a500be0dbf25182d62122ed526a321b9c7953bf7 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Fri, 27 May 2022 13:10:20 +0000 Subject: [PATCH] [FIX] sale: provide a way to recompute line taxes Since #79093, the onchange updating taxes according to fpos was replaced by a compute, but the dependency on the order fpos was not kept to avoid full recomputation of taxes (& potentially other things) when SO fields are modified. Nevertheless, it makes sense in some flows to update the fpos after creation of SOlines, and to want the taxes to be updated accordingly. To provide this ability, a new button is added, following the existing logic to update the prices & discounts when the pricelist is changed. Task - 2865882 X-original-commit: 23ac2e09e19d3ee48018b2940e67048208b65caf Part-of: odoo/odoo#93503 --- addons/sale/i18n/sale.pot | 35 ++++++++++++++++++++++++++ addons/sale/models/sale_order.py | 23 +++++++++++++++++ addons/sale/views/sale_order_views.xml | 12 ++++++++- 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/addons/sale/i18n/sale.pot b/addons/sale/i18n/sale.pot index 50585f72ac1..1c951b42789 100644 --- a/addons/sale/i18n/sale.pot +++ b/addons/sale/i18n/sale.pot @@ -1722,6 +1722,11 @@ msgstr "" msgid "Group By" msgstr "" +#. module: sale +#: model:ir.model.fields,field_description:sale.field_sale_order__show_update_fpos +msgid "Has Fiscal Position Changed" +msgstr "" + #. module: sale #: model:ir.model.fields,field_description:sale.field_sale_order__has_message msgid "Has Message" @@ -2818,6 +2823,13 @@ msgstr "" msgid "Product prices have been recomputed according to pricelist %s." msgstr "" +#. module: sale +#: code:addons/sale/models/sale_order.py:0 +#, python-format +msgid "" +"Product taxes have been recomputed according to fiscal position %s." +msgstr "" + #. module: sale #: model_terms:ir.ui.view,arch_db:sale.res_config_settings_view_form msgid "Product used for down payments" @@ -3014,6 +3026,11 @@ msgstr "" msgid "Recompute all prices based on this pricelist" msgstr "" +#. module: sale +#: model_terms:ir.ui.view,arch_db:sale.view_order_form +msgid "Recompute all taxes based on this fiscal position" +msgstr "" + #. module: sale #: code:addons/sale/controllers/portal.py:0 #, python-format @@ -3698,6 +3715,13 @@ msgid "" "Tech field caching pricelist rule used for price & discount computation" msgstr "" +#. module: sale +#: model:ir.model.fields,help:sale.field_sale_order__show_update_fpos +msgid "" +"Technical Field, True if the fiscal position was changed;\n" +" this will then display a recomputation button" +msgstr "" + #. module: sale #: model:ir.model.fields,help:sale.field_sale_order__show_update_pricelist msgid "" @@ -3997,6 +4021,12 @@ msgid "" "Invoice Analysis report in the Accounting application." msgstr "" +#. module: sale +#: model_terms:ir.ui.view,arch_db:sale.view_order_form +msgid "" +"This will update all taxes based on the currently selected fiscal position." +msgstr "" + #. module: sale #: model_terms:ir.ui.view,arch_db:sale.view_order_form msgid "This will update all unit prices based on the currently set pricelist." @@ -4194,6 +4224,11 @@ msgstr "" msgid "Update Prices" msgstr "" +#. module: sale +#: model_terms:ir.ui.view,arch_db:sale.view_order_form +msgid "Update Taxes" +msgstr "" + #. module: sale #: code:addons/sale/models/sale_order.py:0 #, python-format diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 60ae6f15818..b9961bfcf7c 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -192,6 +192,10 @@ class SaleOrder(models.Model): digits=(12, 6), store=True, precompute=True, help='The rate of the currency to the currency of rate 1 applicable at the date of the order') + show_update_fpos = fields.Boolean( + string="Has Fiscal Position Changed", store=False, + help="Technical Field, True if the fiscal position was changed;\n" + " this will then display a recomputation button") show_update_pricelist = fields.Boolean( string="Has Pricelist Changed", help="Technical Field, True if the pricelist was changed;\n" @@ -624,6 +628,14 @@ class SaleOrder(models.Model): updated_credit = order.partner_id.credit + (order.amount_total * order.currency_rate) order.partner_credit_warning = self.env['account.move']._build_credit_warning_message(order, updated_credit) + @api.onchange('fiscal_position_id') + def _onchange_fpos_id_show_update_fpos(self): + if self.order_line and ( + not self.fiscal_position_id + or (self.fiscal_position_id and self._origin.fiscal_position_id != self.fiscal_position_id) + ): + self.show_update_fpos = True + @api.onchange('partner_id') def _onchange_partner_id_warning(self): if not self.partner_id: @@ -856,6 +868,17 @@ class SaleOrder(models.Model): return False return any(so.state != 'draft' for so in self) + def action_update_taxes(self): + self.ensure_one() + lines_to_recompute = self.order_line.filtered(lambda line: not line.display_type) + lines_to_recompute._compute_tax_id() + self.show_update_fpos = False + if self.partner_id and self.id: + self.message_post(body=_( + "Product taxes have been recomputed according to fiscal position %s.", + self.fiscal_position_id._get_html_link() if self.fiscal_position_id else "", + )) + def update_prices(self): self.ensure_one() lines_to_recompute = self.order_line.filtered(lambda line: not line.display_type) diff --git a/addons/sale/views/sale_order_views.xml b/addons/sale/views/sale_order_views.xml index a1d9dbafa36..fc2e7615099 100644 --- a/addons/sale/views/sale_order_views.xml +++ b/addons/sale/views/sale_order_views.xml @@ -590,7 +590,17 @@ - + +