diff --git a/addons/event_booth_sale/tests/test_event_booth_sale.py b/addons/event_booth_sale/tests/test_event_booth_sale.py index 7f1766b3c31..a0314aa7540 100644 --- a/addons/event_booth_sale/tests/test_event_booth_sale.py +++ b/addons/event_booth_sale/tests/test_event_booth_sale.py @@ -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.") diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index 9b5adf0bf48..a49d4f4b1fd 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -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 # diff --git a/addons/sale/tests/test_sale_prices.py b/addons/sale/tests/test_sale_prices.py index f45f6ed0a39..fc996f10668 100644 --- a/addons/sale/tests/test_sale_prices.py +++ b/addons/sale/tests/test_sale_prices.py @@ -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( diff --git a/addons/sale/views/sale_order_views.xml b/addons/sale/views/sale_order_views.xml index ae5bf447562..9cda7b66ec6 100644 --- a/addons/sale/views/sale_order_views.xml +++ b/addons/sale/views/sale_order_views.xml @@ -265,12 +265,12 @@