[FIX] sale_management: options_lines have correct discount

Step to reproduce:
- Create a pricelist with 20% discount and
 Show discount to the user
- In a SO with public pricelist, add option line OL
- Change pricelist to the one created earlier

Current behaviour:
- OL unit price is 80% of list price
- OL discount is 0%

Behaviour after PR:
- OL unit price is 100% of list price
- OL discount is 20%

opw-2761252

closes odoo/odoo#87640

X-original-commit: 0d4293da09821016d9db56ec1f36fbeff3bf8ef2
Signed-off-by: Damhaut Florian (flda) <flda@odoo.com>
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Florian Damhaut
2022-03-31 11:36:38 +02:00
committed by Victor Feyens
parent e3e7623f21
commit d34f7d38d8
@@ -280,3 +280,61 @@ class TestSaleOrder(TestSaleCommon):
"If a pricelist is set without discount included, the discount "
"shall be computed according to the price unit and the subtotal."
"price")
def test_04_update_pricelist_option_line(self):
"""
This test checks that option line's values are correctly
updated after a pricelist update
"""
# Necessary for _onchange_discount() check
self.env.user.write({
'groups_id': [(4, self.env.ref('product.group_discount_per_so_line').id)],
})
self.sale_order.write({
'sale_order_template_id': self.quotation_template_no_discount.id
})
self.sale_order._onchange_sale_order_template_id()
self.assertEqual(
self.sale_order.sale_order_option_ids[0].price_unit,
self.pub_option_price,
"If no pricelist is set, the unit price shall be the option's product price.")
self.assertEqual(
self.sale_order.sale_order_option_ids[0].discount, 0,
"If no pricelist is set, the discount should be 0.")
self.sale_order.write({
'pricelist_id': self.discount_included_price_list.id,
})
self.sale_order.update_prices()
self.assertEqual(
self.sale_order.sale_order_option_ids[0].price_unit,
self.pl_option_price,
"If a pricelist is set with discount included,"
" the unit price shall be the option's product discounted price.")
self.assertEqual(
self.sale_order.sale_order_option_ids[0].discount, 0,
"If a pricelist is set with discount included,"
" the discount should be 0.")
self.sale_order.write({
'pricelist_id': self.discount_excluded_price_list.id,
})
self.sale_order.update_prices()
self.assertEqual(
self.sale_order.sale_order_option_ids[0].price_unit,
self.pub_option_price,
"If a pricelist is set without discount included,"
" the unit price shall be the option's product sale price.")
self.assertEqual(
self.sale_order.sale_order_option_ids[0].discount,
self.pl_option_discount,
"If a pricelist is set without discount included,"
" the discount should be correctly computed.")