Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] product_packaging_level: Rely on 'qty' field too to compute the qty_per_level field #1595

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion product_packaging_level/models/product_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def _compute_barcode_required_for_gtin(self):
@api.depends(
"product_id",
"product_id.packaging_ids",
"qty",
"packaging_level_id",
"packaging_level_id.code",
)
Expand All @@ -88,7 +89,7 @@ def _get_qty_per_level_mapping(self):
:return: mapping {level.code: qty}
"""
smaller_product_packagings = self.product_id.packaging_ids.filtered(
lambda p: p.id != self.id and self.qty > p.qty > 0.0
lambda p: p.ids != self.ids and self.qty > p.qty > 0.0
)
res = OrderedDict()
for p_pack in smaller_product_packagings.sorted(lambda p: p.qty):
Expand Down
26 changes: 25 additions & 1 deletion product_packaging_level/tests/test_product_packaging_level.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2021 ACSONE SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.exceptions import ValidationError
from odoo.tests import common
from odoo.tests import Form, common


class TestProductPackagingLevel(common.TransactionCase):
Expand Down Expand Up @@ -184,3 +184,27 @@ def test_packaging_qty_per_level(self):
self.assertEqual(self.packaging_10.qty_per_level, "6.0 TEST2; 2.0 TEST3")
# Base packaging has no qty per level
self.assertEqual(self.packaging.qty_per_level, "")

def test_packaging_qty_per_level_form(self):
""" """
self.level_3 = self.env["product.packaging.level"].create(
{
"name": "Packaging Level 3 Test",
"code": "TEST3",
"sequence": 3,
}
)
self.packaging_3 = self.env["product.packaging"].create(
{
"name": "Packaging Test",
"packaging_level_id": self.level_3.id,
"qty": 3.0,
"product_id": self.product.product_variant_ids.id,
}
)
self.assertEqual(self.packaging_3.qty_per_level, "3.0 TEST2")
with Form(self.packaging_3) as pack_form:
pack_form.qty = 9.0
self.assertEqual(pack_form.qty_per_level, "9.0 TEST2")
self.packaging_3.invalidate_recordset()
self.assertEqual(self.packaging_3.qty_per_level, "9.0 TEST2")
Loading