Skip to content

Commit

Permalink
[MIG] product_pack: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ALopez-Adhoc committed Jan 10, 2025
1 parent 6f321f0 commit 8a749f9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 32 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": "17.0.2.0.0",
"version": "18.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
1 change: 0 additions & 1 deletion product_pack/models/product_pack_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ def _pack_line_price_compute(
# If the component is a pack
for pack in packs:
pack_prices[pack.id] = pack.lst_price

Check warning on line 77 in product_pack/models/product_pack_line.py

View check run for this annotation

Codecov / codecov/patch

product_pack/models/product_pack_line.py#L77

Added line #L77 was not covered by tests

# else
no_pack_prices = no_packs._price_compute(
price_type, uom, currency, company, date
Expand Down
26 changes: 9 additions & 17 deletions product_pack/models/product_pricelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class Pricelist(models.Model):
_inherit = "product.pricelist"

def _get_product_price(self, product, quantity, uom=None, date=False, **kwargs):
def _get_product_price(self, product, *args, **kwargs):
"""Compute the pricelist price for the specified pack product, qty & uom.
:returns: unit price of the pack product + components,
Expand All @@ -20,32 +20,24 @@ def _get_product_price(self, product, quantity, uom=None, date=False, **kwargs):
):
pack_price = 0
else:
pack_price = self._compute_price_rule(
product, quantity, uom=uom, date=date, **kwargs
)[product.id][0]
pack_price = self._compute_price_rule(product, *args, **kwargs)[
product.id
][0]

for line in product.sudo().pack_line_ids:
pack_price += line._get_pack_line_price(
self, quantity, uom=uom, date=date, **kwargs
)
pack_price += line._get_pack_line_price(self, *args, **kwargs)
return pack_price
else:
return super()._get_product_price(
product=product, quantity=quantity, uom=uom, date=date, **kwargs
)
return super()._get_product_price(product, *args, **kwargs)

def _get_products_price(self, products, quantity, uom=None, date=False, **kwargs):
def _get_products_price(self, products, *args, **kwargs):
"""Compute the pricelist price for the specified pack product, qty & uom.
:returns: unit price of the pack product + components,
considering pricelist rules
"""
packs, no_packs = products.split_pack_products()
res = super()._get_products_price(
no_packs, quantity=quantity, uom=uom, date=date, **kwargs
)
res = super()._get_products_price(no_packs, *args, **kwargs)

Check warning on line 40 in product_pack/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

product_pack/models/product_pricelist.py#L39-L40

Added lines #L39 - L40 were not covered by tests
for pack in packs:
res[pack.id] = self._get_product_price(
product=pack, quantity=quantity, uom=uom, date=date, **kwargs
)
res[pack.id] = self._get_product_price(pack, *args, **kwargs)
return res

Check warning on line 43 in product_pack/models/product_pricelist.py

View check run for this annotation

Codecov / codecov/patch

product_pack/models/product_pricelist.py#L42-L43

Added lines #L42 - L43 were not covered by tests
4 changes: 2 additions & 2 deletions product_pack/views/product_pack_line_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<field name="name">product.pack.line.tree</field>
<field name="model">product.pack.line</field>
<field name="arch" type="xml">
<tree editable="bottom">
<list editable="bottom">
<field name="product_id" />
<field name="quantity" />
</tree>
</list>
</field>
</record>
</odoo>
17 changes: 6 additions & 11 deletions product_pack/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,13 @@
name="invisible"
>product_variant_count &gt; 1 or not pack_ok</attribute>
</page>
<group name="group_pack">
<group string="Pack Products" colspan="4">
<field name="id" invisible="1" />
<p invisible="id">You must save first to add pack lines</p>
</group>
<field
name="pack_line_ids"
nolabel="1"
colspan="4"
readonly="not id"
/>
<group name="group_pack">
<group string="Pack Products" colspan="4">
<field name="id" invisible="1" />
<p invisible="id">You must save first to add pack lines</p>
</group>
<field name="pack_line_ids" nolabel="1" colspan="4" readonly="not id" />
</group>
</field>
</record>
</odoo>

0 comments on commit 8a749f9

Please sign in to comment.