[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
This commit is contained in:
@@ -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 <b>%s<b>."
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -590,7 +590,17 @@
|
||||
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_create_edit': True}"/>
|
||||
</group>
|
||||
<group name="sale_info" string="Invoicing and Payments">
|
||||
<field name="fiscal_position_id" options="{'no_create': True}"/>
|
||||
<field name="show_update_fpos" invisible="1"/>
|
||||
<label for="fiscal_position_id"/>
|
||||
<div class="o_row">
|
||||
<field name="fiscal_position_id" options="{'no_create': True}"/>
|
||||
<button name="action_update_taxes" type="object"
|
||||
string=" Update Taxes"
|
||||
help="Recompute all taxes based on this fiscal position"
|
||||
class="btn-link mb-1 px-0" icon="fa-refresh"
|
||||
confirm="This will update all taxes based on the currently selected fiscal position."
|
||||
attrs="{'invisible': ['|', ('show_update_fpos', '=', False), ('state', 'in', ['sale', 'done','cancel'])]}"/>
|
||||
</div>
|
||||
<field name="analytic_account_id" context="{'default_partner_id':partner_invoice_id, 'default_name':name}" attrs="{'readonly': [('invoice_count','!=',0),('state','=','sale')]}" groups="analytic.group_analytic_accounting" force_save="1"/>
|
||||
<field name="invoice_status" states="sale,done" groups="base.group_no_one"/>
|
||||
</group>
|
||||
|
||||
Reference in New Issue
Block a user