Skip to content

Commit

Permalink
[MIG] stock_product_pack: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ALopez-Adhoc authored and augusto-weiss committed Dec 9, 2024
1 parent 054aebb commit 3e67c13
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 23 deletions.
2 changes: 1 addition & 1 deletion stock_product_pack/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Stock product Pack",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"category": "Warehouse",
"summary": "This module allows you to get the right available quantities "
"of the packs",
Expand Down
36 changes: 23 additions & 13 deletions stock_product_pack/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,40 @@ def _compute_quantities_dict(
self, lot_id, owner_id, package_id, from_date=False, to_date=False
):
packs = self.filtered("pack_ok")
res = super(ProductProduct, self - packs)._compute_quantities_dict(
subproducts = packs.pack_line_ids.filtered(
lambda p: p.product_id.type == "consu"
).mapped("product_id")
res = super(ProductProduct, self | subproducts)._compute_quantities_dict(
lot_id, owner_id, package_id, from_date=from_date, to_date=to_date
)
for product in packs.with_context(prefetch_fields=False):
for pack in packs.with_context(prefetch_fields=False):
pack_qty_available = []
pack_virtual_available = []
pack_free_qty = []
subproducts = product.pack_line_ids.filtered(
lambda p: p.product_id.detailed_type == "product"
)
for subproduct in subproducts:
subproduct_stock = subproduct.product_id
sub_qty = subproduct.quantity

for line in pack.pack_line_ids.filtered(
lambda p: p.product_id.type == "consu"
):
sub_qty = line.quantity
if sub_qty:
pack_qty_available.append(
math.floor(subproduct_stock.qty_available / sub_qty)
math.floor(
(
res[line.product_id.id]["qty_available"]
- res[line.product_id.id]["outgoing_qty"]
)
/ sub_qty
)
)
pack_virtual_available.append(
math.floor(subproduct_stock.virtual_available / sub_qty)
math.floor(
res[line.product_id.id]["virtual_available"] / sub_qty
)
)
pack_free_qty.append(
math.floor(subproduct_stock.free_qty / sub_qty)
math.floor(res[line.product_id.id]["free_qty"] / sub_qty)
)
res[product.id] = {
res[pack.id] = {
"qty_available": (pack_qty_available and min(pack_qty_available) or 0),
"free_qty": (pack_free_qty and min(pack_free_qty) or 0),
"incoming_qty": 0,
Expand Down Expand Up @@ -71,7 +81,7 @@ def _compute_quantities(self):
service products if they are pack.
"""
service_pack_products = self.filtered(
lambda p: p.detailed_type == "service" and p.pack_ok
lambda p: p.type == "service" and p.pack_ok
)
result = super(
ProductProduct, self - service_pack_products
Expand Down
34 changes: 26 additions & 8 deletions stock_product_pack/tests/test_stock_product_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,44 @@ def setUpClass(cls):
category_all_id = cls.env.ref("product.product_category_all").id
cls.product_obj = cls.env["product.product"]
cls.stock_rule_obj = cls.env["stock.rule"]
# The model stock doesn't add anymore the 'product'
# selection to the product type.
# Thus the type is changed to 'consu'
component_1 = cls.product_obj.create(
{
"name": "Component 1",
"detailed_type": "product",
"type": "consu",
"is_storable": True,
"categ_id": category_all_id,
}
)
component_2 = cls.product_obj.create(
{
"name": "Component 2",
"detailed_type": "product",
"type": "consu",
"is_storable": True,
"categ_id": category_all_id,
}
)
component_3 = cls.product_obj.create(
{
"name": "Component 3",
"detailed_type": "service",
"type": "service",
"categ_id": category_all_id,
}
)
component_4 = cls.product_obj.create(
{
"name": "Component 4",
"detailed_type": "consu",
"type": "consu",
"is_storable": True,
"categ_id": category_all_id,
}
)
cls.pack_dc = cls.product_obj.create(
{
"name": "Pack",
"detailed_type": "product",
"type": "consu",
"pack_ok": True,
"pack_type": "detailed",
"pack_component_price": "detailed",
Expand Down Expand Up @@ -94,7 +100,7 @@ def setUpClass(cls):
cls.pack_dc_with_dm = cls.product_obj.create(
{
"name": "Pack With storeable and not move product",
"detailed_type": "product",
"type": "consu",
"pack_ok": True,
"dont_create_move": True,
"pack_type": "detailed",
Expand Down Expand Up @@ -161,6 +167,18 @@ def test_compute_quantities_dict(self):
"location_dest_id": location_dest_id,
},
),
(
0,
0,
{
"name": "incoming_move_test_03",
"product_id": components[3].id,
"product_uom_qty": 9,
"product_uom": components[3].uom_id.id,
"location_id": location_id,
"location_dest_id": location_dest_id,
},
),
],
}
)
Expand All @@ -186,7 +204,7 @@ def test_pack_with_dont_move_the_parent(self):
def create_orderpoint(product, qty_min, qty_max, location, group):
return self.env["stock.warehouse.orderpoint"].create(
{
"name": "OP/%s" % product.name,
"name": f"OP/{product.name}",
"product_id": product.id,
"product_min_qty": qty_min,
"product_max_qty": qty_max,
Expand All @@ -203,7 +221,7 @@ def create_orderpoint(product, qty_min, qty_max, location, group):
self.env.ref("stock.stock_location_stock"),
pg,
)
self.env["stock.scheduler.compute"].create({}).procure_calculation()
# self.env["stock.scheduler.compute"].create({}).procure_calculation()
picking_ids = self.env["stock.picking"].search([("group_id", "=", pg.id)])
# we need to ensure that only the compents of the packs are in the moves.
self.assertFalse(self.pack_dc_with_dm in picking_ids.move_ids.product_id)
2 changes: 1 addition & 1 deletion stock_product_pack/views/product_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<field name="pack_modifiable" position="after">
<field
name="dont_create_move"
invisible="not pack_ok or detailed_type == 'service'"
invisible="not pack_ok or type == 'service'"
/>
</field>
</field>
Expand Down

0 comments on commit 3e67c13

Please sign in to comment.