[IMP] sale: rename update_prices method

make it clear it's expected to be called from the frontend, prefixing it
with action_.
Also split the method to have an utilitary method recomputing all prices,
to use in the tests and/or business code (without the chatter message).

Part-of: odoo/odoo#98068
This commit is contained in:
Victor Feyens
2022-09-01 19:16:48 +02:00
parent 7ca4163517
commit cc5c83e01c
9 changed files with 30 additions and 25 deletions
@@ -67,7 +67,7 @@ class TestEventBoothSale(TestEventBoothSaleWData):
"Total amount should be the sum of the booths prices with 10% taxes ($40.0 + $4.0)")
self.event_booth_category_1.write({'price': 100.0})
sale_order.update_prices()
sale_order._recompute_prices()
self.assertNotEqual(self.booth_1.price, self.event_booth_product.list_price,
"Booth price should be different from product price.")
+12 -7
View File
@@ -914,22 +914,27 @@ class SaleOrder(models.Model):
self.fiscal_position_id._get_html_link() if self.fiscal_position_id else "",
))
def update_prices(self):
def action_update_prices(self):
self.ensure_one()
self._recompute_prices()
if self.pricelist_id:
self.message_post(body=_(
"Product prices have been recomputed according to pricelist %s.",
self.pricelist_id._get_html_link(),
))
def _recompute_prices(self):
lines_to_recompute = self.order_line.filtered(lambda line: not line.display_type)
lines_to_recompute.invalidate_recordset(['pricelist_item_id'])
lines_to_recompute._compute_price_unit()
# Special case: we want to overwrite the existing discount on update_prices call
# Special case: we want to overwrite the existing discount on _recompute_prices call
# i.e. to make sure the discount is correctly reset
# if pricelist discount_policy is different than when the price was first computed.
lines_to_recompute.discount = 0.0
lines_to_recompute._compute_discount()
self.show_update_pricelist = False
if self.partner_id and self.id:
self.message_post(body=_(
"Product prices have been recomputed according to pricelist %s.",
self.pricelist_id._get_html_link(),
))
# INVOICING #
+6 -6
View File
@@ -87,7 +87,7 @@ class TestSalePrices(SaleCommon):
)
self.pricelist.discount_policy = 'without_discount'
self.empty_order.update_prices()
self.empty_order._recompute_prices()
self.assertEqual(
discounted_lines.mapped('price_unit'),
[product_price, product_price, product_dozen_price, product_dozen_price])
@@ -474,12 +474,12 @@ class TestSalePrices(SaleCommon):
def test_update_prices(self):
"""Test prices recomputation on SO's.
`update_prices` is shown as a button to update
`_recompute_prices` is shown as a button to update
prices when the pricelist was changed.
"""
sale_order = self.sale_order
so_amount = sale_order.amount_total
sale_order.update_prices()
sale_order._recompute_prices()
self.assertEqual(
sale_order.amount_total, so_amount,
"Updating the prices of an unmodified SO shouldn't modify the amounts")
@@ -492,14 +492,14 @@ class TestSalePrices(SaleCommon):
})
]
pricelist.discount_policy = "without_discount"
sale_order.update_prices()
sale_order._recompute_prices()
self.assertTrue(all(line.discount == 5 for line in sale_order.order_line))
self.assertEqual(sale_order.amount_undiscounted, so_amount)
self.assertEqual(sale_order.amount_total, 0.95*so_amount)
pricelist.discount_policy = "with_discount"
sale_order.update_prices()
sale_order._recompute_prices()
self.assertTrue(all(line.discount == 0 for line in sale_order.order_line))
self.assertEqual(sale_order.amount_undiscounted, so_amount)
@@ -561,7 +561,7 @@ class TestSalePrices(SaleCommon):
})
# Update Prices
self.empty_order.update_prices()
self.empty_order._recompute_prices()
# Check that the discount displayed is the correct one
self.assertEqual(
+2 -2
View File
@@ -265,12 +265,12 @@
<label for="pricelist_id" groups="product.group_product_pricelist"/>
<div groups="product.group_product_pricelist" class="o_row">
<field name="pricelist_id" options="{'no_open':True,'no_create': True}"/>
<button name="update_prices" type="object"
<button name="action_update_prices" type="object"
string=" Update Prices"
help="Recompute all prices based on this pricelist"
class="btn-link mb-1 px-0" icon="fa-refresh"
confirm="This will update all unit prices based on the currently set pricelist."
attrs="{'invisible': ['|', ('show_update_pricelist', '=', False), ('state', 'in', ['sale', 'done','cancel'])]}"/>
attrs="{'invisible': ['|', ('show_update_pricelist', '=', False), ('state', 'in', ['sale', 'done', 'cancel'])]}"/>
</div>
<field name="company_id" invisible="1"/>
<field name="currency_id" invisible="1"/>
+2 -2
View File
@@ -434,9 +434,9 @@ class SaleOrder(models.Model):
return invoiceable_lines
return self.env['sale.order.line']
def update_prices(self):
def _recompute_prices(self):
"""Recompute coupons/promotions after pricelist prices reset."""
super().update_prices()
super()._recompute_prices()
if any(line.is_reward_line for line in self.order_line):
self._update_programs_and_rewards()
+3 -3
View File
@@ -118,9 +118,9 @@ class SaleOrder(models.Model):
order.sale_order_template_id.mail_template_id.send_mail(order.id)
return res
def update_prices(self):
super().update_prices()
# Special case: we want to overwrite the existing discount on update_prices call
def _recompute_prices(self):
super()._recompute_prices()
# Special case: we want to overwrite the existing discount on _recompute_prices call
# i.e. to make sure the discount is correctly reset
# if pricelist discount_policy is different than when the price was first computed.
self.sale_order_option_ids.discount = 0.0
@@ -280,7 +280,7 @@ class TestSaleOrder(SaleManagementCommon):
self.sale_order.write({
'pricelist_id': self.discount_included_price_list.id,
})
self.sale_order.update_prices()
self.sale_order._recompute_prices()
self.assertEqual(
self.sale_order.sale_order_option_ids[0].price_unit,
@@ -296,7 +296,7 @@ class TestSaleOrder(SaleManagementCommon):
self.sale_order.write({
'pricelist_id': self.discount_excluded_price_list.id,
})
self.sale_order.update_prices()
self.sale_order._recompute_prices()
self.assertEqual(
self.sale_order.sale_order_option_ids[0].price_unit,
+1 -1
View File
@@ -116,7 +116,7 @@ class SaleOrder(models.Model):
self._compute_pricelist_id()
if update_pricelist or previous_pricelist_id != self.pricelist_id.id:
self.update_prices()
self._recompute_prices()
def _cart_update(self, product_id, line_id=None, add_qty=0, set_qty=0, **kwargs):
""" Add or set product quantity, add_qty can be negative """
+1 -1
View File
@@ -394,7 +394,7 @@ class Website(models.Model):
if update_pricelist:
request.session['website_sale_current_pl'] = pricelist_id
sale_order_sudo.write({'pricelist_id': pricelist_id})
sale_order_sudo.update_prices()
sale_order_sudo._recompute_prices()
return sale_order_sudo