Skip to content
Snippets Groups Projects
Commit f34e4415 authored by Nasreddin Boulif (bon)'s avatar Nasreddin Boulif (bon)
Browse files

[FIX] website_sale: Display pricelist price if no price_unit


Steps to reproduce:

  - Install website_sale module
  - Enable discount and advanced pricelist in settings
  - Create product with sale price 0$ and set a website in
  - eCommerce + publish the product
  - Create pricelist PPP with Discount Policy as
  - "Show public price & discount to the customer" and selectable in the website
  - Go to the product and set an extra price of 10$ for the new pricelist
  - Go to the product in the eshop and select the pricelist PPP
  - Add the product to the shop cart

Issue:

  The price displayed is 0$ instead of 10$.

Cause:

  Since price_unit equal 0$, not possible to calculate the discount and
  therefore using the 0$ value.

Solution:

  Use price of pricelist in case 'discount_policy' is 'without_discount'
  and price_unit equal 0$.

opw-2652192
Forward-Port-Of: #78570

Cherry pick of 32d34ffb04b3c6a8397c8ff7eb4e8a3dd9fb8a95

closes odoo/odoo#78701

Signed-off-by: default avatarbon-odoo <nboulif@users.noreply.github.com>
parent 86381c60
Branches
Tags
No related merge requests found
......@@ -125,6 +125,10 @@ class SaleOrder(models.Model):
# but we still want to use the price defined on the pricelist
discount = 0
pu = price
else:
# In case the price_unit equal 0 and therefore not able to calculate the discount,
# we fallback on the price defined on the pricelist.
pu = price
else:
pu = product.price
if order.pricelist_id and order.partner_id:
......
......@@ -241,6 +241,44 @@ class TestWebsitePriceList(TransactionCase):
self.assertEqual(sol.price_reduce, 27.75, 'Both reductions should be applied')
self.assertEqual(sol.price_total, 13875)
def test_pricelist_with_no_list_price(self):
product = self.env['product.product'].create({
'name': 'Super Product',
'list_price': 0,
'taxes_id': False,
})
current_website = self.env['website'].get_current_website()
website_pricelist = current_website.get_current_pricelist()
website_pricelist.write({
'discount_policy': 'without_discount',
'item_ids': [(5, 0, 0), (0, 0, {
'applied_on': '1_product',
'product_tmpl_id': product.product_tmpl_id.id,
'min_quantity': 0,
'compute_price': 'fixed',
'fixed_price': 10,
})]
})
so = self.env['sale.order'].create({
'partner_id': self.env.user.partner_id.id,
'order_line': [(0, 0, {
'name': product.name,
'product_id': product.id,
'product_uom_qty': 5,
'product_uom': product.uom_id.id,
'price_unit': product.list_price,
'tax_id': False,
})]
})
sol = so.order_line
self.assertEqual(sol.price_total, 0)
so.pricelist_id = website_pricelist
with MockRequest(self.env, website=current_website, sale_order_id=so.id):
so._cart_update(product_id=product.id, line_id=sol.id, set_qty=5)
self.assertEqual(sol.price_unit, 10.0, 'Pricelist price should be applied')
self.assertEqual(sol.price_reduce, 10.0, 'Pricelist price should be applied')
self.assertEqual(sol.price_total, 50.0)
def simulate_frontend_context(self, website_id=1):
# Mock this method will be enough to simulate frontend context in most methods
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment