Skip to content

Commit

Permalink
Merge commit 'refs/pull/133/head' of https://github.com/oca/product-pack
Browse files Browse the repository at this point in the history
 into 16.0-2900
  • Loading branch information
docker-odoo committed Jul 4, 2023
2 parents e4eeaca + b1500be commit 2711de9
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 5 deletions.
10 changes: 9 additions & 1 deletion product_pack/models/product_pack_line.py
Expand Up @@ -54,6 +54,14 @@ def _check_recursion(self):
)
pack_lines = pack_lines.mapped("product_id.pack_line_ids")

def get_price(self):
def get_price(self, price_type=None, currency=False, company=False, date=False):
self.ensure_one()
if price_type and price_type == "standard_price":
price_currency = self.product_id.cost_currency_id
company = company or self.env.company
date = date or fields.Date.context_today(self)
price = self.product_id["standard_price"]
if price_currency != currency:
price = price_currency._convert(price, currency, company, date)
return price * self.quantity
return self.product_id.lst_price * self.quantity
2 changes: 1 addition & 1 deletion product_pack/models/product_product.py
Expand Up @@ -40,7 +40,7 @@ def price_compute(
for product in packs.with_context(prefetch_fields=False):
pack_price = 0.0
for pack_line in product.sudo().pack_line_ids:
pack_price += pack_line.get_price()
pack_price += pack_line.get_price(price_type, currency, company, date)
pricelist_id_or_name = self._context.get("pricelist")
# if there is a pricelist on the context the returned prices are on
# that currency but, if the pack product has a different currency
Expand Down
6 changes: 4 additions & 2 deletions sale_product_pack/models/product_pack_line.py
Expand Up @@ -46,6 +46,8 @@ def get_sale_order_line_vals(self, line, order):
)
return vals

def get_price(self):
def get_price(self, price_type=None, currency=False, company=False, date=False):
self.ensure_one()
return super().get_price() * (1 - self.sale_discount / 100.0)
return super().get_price(price_type, currency, company, date) * (
1 - self.sale_discount / 100.0
)
25 changes: 24 additions & 1 deletion sale_product_pack/tests/test_sale_product_pack.py
Expand Up @@ -42,6 +42,23 @@ def setUpClass(cls):
],
}
)
cls.based_on_cost_pricelist = cls.env["product.pricelist"].create(
{
"name": "Based on Cost",
"company_id": cls.env.company.id,
"item_ids": [
(
0,
0,
{
"applied_on": "3_global",
"compute_price": "formula",
"base": "standard_price",
},
)
],
}
)
cls.sale_order = cls.env["sale.order"].create(
{
"company_id": cls.env.company.id,
Expand Down Expand Up @@ -160,14 +177,20 @@ def test_create_totalized_price_order_line(self):
# Pack price is equal to the sum of component prices
self.assertAlmostEqual(line.price_subtotal, 2662.5)
self.assertAlmostEqual(self._get_component_prices_sum(product_tp), 2662.5)

# Update pricelist with a discount
self.sale_order.pricelist_id = self.discount_pricelist
self.sale_order.action_update_prices()
self.assertAlmostEqual(line.price_subtotal, 2396.25)
self.assertEqual(
(self.sale_order.order_line - line).mapped("price_subtotal"), [0, 0, 0]
)
# Update pricelist to based on cost pricelist
self.sale_order.pricelist_id = self.based_on_cost_pricelist
self.sale_order.action_update_prices()
self.assertAlmostEqual(line.price_subtotal, 2424.00)
self.assertEqual(
(self.sale_order.order_line - line).mapped("price_subtotal"), [0, 0, 0]
)

def test_create_non_detailed_price_order_line(self):
product_ndtp = self.env.ref("product_pack.product_pack_cpu_non_detailed")
Expand Down

0 comments on commit 2711de9

Please sign in to comment.