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 @@ - + +