Skip to content

Commit

Permalink
[MIG] product_pack: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
FrancoMaxime committed Feb 23, 2023
1 parent ea8ff51 commit 26e1429
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
2 changes: 1 addition & 1 deletion product_pack/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Product Pack",
"version": "15.0.1.0.1",
"version": "16.0.1.0.0",
"category": "Product",
"summary": "This module allows you to set a product as a Pack",
"website": "https://github.com/OCA/product-pack",
Expand Down
2 changes: 1 addition & 1 deletion product_pack/models/product_pack_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ def _check_recursion(self):

def get_price(self):
self.ensure_one()
return self.product_id.price * self.quantity
return self.product_id.lst_price * self.quantity
23 changes: 8 additions & 15 deletions product_pack/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,16 @@
class ProductPricelist(models.Model):
_inherit = "product.pricelist"

def _compute_price_rule(self, products_qty_partner, date=False, uom_id=False):
def _compute_price_rule(self, products, qty, uom=None, date=False, **kwargs):
"""Don't call super when dealing with detailed and non detailed packs,
as the computations done after calling `price_compute` modify the final returned
price, so we compute it directly in these cases.
"""
products_qty_partner_super = [
(s[0], s[1], s[2])
for s in products_qty_partner
if not s[0] in s[0].split_pack_products()[0]
]
res = super()._compute_price_rule(
products_qty_partner_super, date=date, uom_id=uom_id
)
for product, _, _ in products_qty_partner:
if product in product.split_pack_products()[0]:
res[product.id] = (
product.price_compute("list_price")[product.id],
False,
)
packs, no_packs = products.split_pack_products()
res = super()._compute_price_rule(no_packs, qty, uom, date, **kwargs)
for product in packs:
res[product.id] = (
product.price_compute("list_price")[product.id],
False,
)
return res
6 changes: 4 additions & 2 deletions product_pack/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ def split_pack_products(self):
packs = self.filtered(lambda p: p.product_tmpl_id._is_pack_to_be_handled())
return packs, (self - packs)

def price_compute(self, price_type, uom=False, currency=False, company=False):
def price_compute(
self, price_type, uom=False, currency=False, company=False, date=False
):
packs, no_packs = self.split_pack_products()
prices = super(ProductProduct, no_packs).price_compute(
price_type, uom, currency, company
price_type, uom, currency, company, date
)
for product in packs.with_context(prefetch_fields=False):
pack_price = 0.0
Expand Down
4 changes: 4 additions & 0 deletions product_pack/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@
* `Sygel <https://www.sygel.es>`_:

* Manuel Regidor

* `Acsone <https://www.acsone.eu/>`_:

* Maxime Franco
10 changes: 6 additions & 4 deletions product_pack/tests/test_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_product_in_pack_unique(self):
def test_get_pack_line_price(self):
# Check pack line price from product one
component = self.env.ref("product_pack.pack_cpu_detailed_components_1")
component.product_id.price = 30.0
component.product_id.list_price = 30.0
self.assertEqual(
30.0,
self.cpu_detailed.pack_line_ids.filtered(
Expand All @@ -70,10 +70,12 @@ def test_get_pack_lst_price(self):
# Check pack lst_price if totalized from components
pack = self.env.ref("product_pack.product_pack_cpu_detailed_totalized")
component_1 = self.env.ref("product_pack.pack_cpu_detailed_totalized_1")
component_1.product_id.price = 30.0
component_1.product_id.list_price = 30.0
component_2 = self.env.ref("product_pack.pack_cpu_detailed_totalized_3")
component_2.product_id.price = 15.0
self.assertEqual(45.0, pack.lst_price)
component_2.product_id.list_price = 15.0
component_3 = self.env.ref("product_pack.pack_cpu_detailed_components_4")
component_3.product_id.list_price = 5.0
self.assertEqual(50.0, pack.lst_price)

def test_pack_company(self):
# Try to assign pack lines with product that do not belong to pack
Expand Down

0 comments on commit 26e1429

Please sign in to comment.