Skip to content

Commit

Permalink
[18.0][FIX][MIG] sale_product_pack: Test
Browse files Browse the repository at this point in the history
  • Loading branch information
augusto-weiss committed Dec 9, 2024
1 parent 3913731 commit 03928b1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 28 deletions.
36 changes: 18 additions & 18 deletions sale_product_pack/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ To use this module, you need to:
Known issues / Roadmap
======================

- If this module is installed and stock module is installed too, when
you create a Sale order for a *Non detailed* Pack and you confirm it,
a *Stock picking* is not created with the storable components of that
Pack. So, add a new module called *sale_stock_product_pack* that adds
that feature.
- If this module is installed and stock module is installed too, when
you create a Sale order for a *Non detailed* Pack and you confirm it,
a *Stock picking* is not created with the storable components of that
Pack. So, add a new module called *sale_stock_product_pack* that adds
that feature.

Bug Tracker
===========
Expand All @@ -88,28 +88,28 @@ Authors
Contributors
------------

- `Tecnativa <https://www.tecnativa.com>`__:
- `Tecnativa <https://www.tecnativa.com>`__:

- Ernesto Tejeda
- Pedro M. Baeza
- Ernesto Tejeda
- Pedro M. Baeza

- `Akretion <https://akretion.com>`__:
- `Akretion <https://akretion.com>`__:

- Raphaël Reverdy
- Raphaël Reverdy

- `Open Source Integrators <https://opensourceintegrators.eu>`__:
- `Open Source Integrators <https://opensourceintegrators.eu>`__:

- Daniel Reis <[email protected]>
- Daniel Reis <[email protected]>

- `Acsone <https://www.acsone.eu/>`__:
- `Acsone <https://www.acsone.eu/>`__:

- Maxime Franco
- Maxime Franco

- `ADHOC SA <https://www.adhoc.com.ar>`__:
- `ADHOC SA <https://www.adhoc.com.ar>`__:

- Bruno Zanotti
- Augusto Weiss
- Nicolas Col
- Bruno Zanotti
- Augusto Weiss
- Nicolas Col

Maintainers
-----------
Expand Down
22 changes: 14 additions & 8 deletions sale_product_pack/models/sale_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def _get_pricelist_price(self):
"""
price = super()._get_pricelist_price()

# if self.product_id.product_tmpl_id._is_pack_to_be_handled() and not self.pricelist_item_id.base == 'pricelist':
if self.product_id.product_tmpl_id._is_pack_to_be_handled():
price = self.order_id.pricelist_id._get_product_price(
product=self.product_id.product_tmpl_id, quantity=1.0
Expand All @@ -149,17 +150,22 @@ def _get_pricelist_price(self):
def _get_pack_line_discount(self):
"""returns the discount settled in the parent pack lines"""
self.ensure_one()
discount = 0.0
if self.pack_parent_line_id.pack_component_price == "detailed":
for pack_line in self.pack_parent_line_id.product_id.pack_line_ids:
if pack_line.product_id == self.product_id:
discount = pack_line.sale_discount
break
return discount
pack_line_discount = self.pack_parent_line_id.product_id.pack_line_ids.filtered(
lambda p: p.product_id == self.product_id
).sale_discount
total_discount = (
self.discount
+ pack_line_discount
- (self.discount * pack_line_discount) / 100
)
return total_discount

@api.depends("product_id", "product_uom", "product_uom_qty")
def _compute_discount(self):
res = super()._compute_discount()
for pack_line in self.filtered("pack_parent_line_id"):
pack_line.discount = pack_line._get_pack_line_discount()
if self.pack_parent_line_id.pack_component_price == "detailed":
pack_line.discount = pack_line._get_pack_line_discount()
else:
pack_line.discount = 0.0
return res
50 changes: 48 additions & 2 deletions sale_product_pack/tests/test_sale_product_pack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2019 Tecnativa - Ernesto Tejeda
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo.addons.base.tests.common import BaseCommon


Expand All @@ -10,7 +11,7 @@ def setUpClass(cls):
super().setUpClass()
pricelist = cls.env["product.pricelist"].create(
{
"name": "Test",
"name": "Default",
"company_id": cls.env.company.id,
"item_ids": [
(
Expand All @@ -27,7 +28,7 @@ def setUpClass(cls):
)
cls.discount_pricelist = cls.env["product.pricelist"].create(
{
"name": "Discount",
"name": "Discount (10%)",
"company_id": cls.env.company.id,
"item_ids": [
(
Expand All @@ -42,6 +43,25 @@ def setUpClass(cls):
],
}
)
cls.discount_based_on_pricelist = cls.env["product.pricelist"].create(
{
"name": "Discount (5%) based on Pricelist Discount(10%)",
"company_id": cls.env.company.id,
"item_ids": [
(
0,
0,
{
"applied_on": "3_global",
"compute_price": "percentage",
"percent_price": 5,
"base": "pricelist",
"base_pricelist_id": cls.discount_pricelist.id,
},
)
],
}
)
cls.sale_order = cls.env["sale.order"].create(
{
"company_id": cls.env.company.id,
Expand Down Expand Up @@ -100,6 +120,14 @@ def test_create_components_price_order_line(self):
(self.sale_order.order_line - line).mapped("price_subtotal"),
[1579.5, 20.25, 796.5],
)
# Update pricelist with a pricelist based on pricelist
self.sale_order.pricelist_id = self.discount_based_on_pricelist
self.sale_order.action_update_prices()
self.assertAlmostEqual(line.price_subtotal, 26.29)
self.assertEqual(
(self.sale_order.order_line - line).mapped("price_subtotal"),
[1500.53, 19.24, 756.68],
)

def test_create_ignored_price_order_line(self):
product_tp = self.env.ref("product_pack.product_pack_cpu_detailed_ignored")
Expand Down Expand Up @@ -134,6 +162,13 @@ def test_create_ignored_price_order_line(self):
self.assertEqual(
(self.sale_order.order_line - line).mapped("price_subtotal"), [0, 0, 0]
)
# Update pricelist with a pricelist based on pricelist
self.sale_order.pricelist_id = self.discount_based_on_pricelist
self.sale_order.action_update_prices()
self.assertAlmostEqual(line.price_subtotal, 26.29)
self.assertEqual(
(self.sale_order.order_line - line).mapped("price_subtotal"), [0, 0, 0]
)

def test_create_totalized_price_order_line(self):
product_tp = self.env.ref("product_pack.product_pack_cpu_detailed_totalized")
Expand Down Expand Up @@ -168,6 +203,13 @@ def test_create_totalized_price_order_line(self):
self.assertEqual(
(self.sale_order.order_line - line).mapped("price_subtotal"), [0, 0, 0]
)
# Update pricelist with a pricelist based on pricelist
self.sale_order.pricelist_id = self.discount_based_on_pricelist
self.sale_order.action_update_prices()
self.assertAlmostEqual(line.price_subtotal, 2276.44)
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 All @@ -190,6 +232,10 @@ def test_create_non_detailed_price_order_line(self):
self.sale_order.pricelist_id = self.discount_pricelist
self.sale_order.action_update_prices()
self.assertAlmostEqual(line.price_subtotal, 2396.25)
# Update pricelist with a pricelist based on pricelist
self.sale_order.pricelist_id = self.discount_based_on_pricelist
self.sale_order.action_update_prices()
self.assertAlmostEqual(line.price_subtotal, 2276.44)

def test_update_qty(self):
# Ensure the quantities are always updated
Expand Down

0 comments on commit 03928b1

Please sign in to comment.