Skip to content

Commit dbecfd2

Browse files
committed
[MIG] stock_product_pack: Migration to 18.0
1 parent 054aebb commit dbecfd2

File tree

4 files changed

+51
-23
lines changed

4 files changed

+51
-23
lines changed

Diff for: stock_product_pack/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
66
{
77
"name": "Stock product Pack",
8-
"version": "17.0.1.0.0",
8+
"version": "18.0.1.0.0",
99
"category": "Warehouse",
1010
"summary": "This module allows you to get the right available quantities "
1111
"of the packs",

Diff for: stock_product_pack/models/product_product.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,40 @@ def _compute_quantities_dict(
1414
self, lot_id, owner_id, package_id, from_date=False, to_date=False
1515
):
1616
packs = self.filtered("pack_ok")
17-
res = super(ProductProduct, self - packs)._compute_quantities_dict(
17+
subproducts = packs.pack_line_ids.filtered(
18+
lambda p: p.product_id.type == "consu"
19+
).mapped("product_id")
20+
res = super(ProductProduct, self | subproducts)._compute_quantities_dict(
1821
lot_id, owner_id, package_id, from_date=from_date, to_date=to_date
1922
)
20-
for product in packs.with_context(prefetch_fields=False):
23+
for pack in packs.with_context(prefetch_fields=False):
2124
pack_qty_available = []
2225
pack_virtual_available = []
2326
pack_free_qty = []
24-
subproducts = product.pack_line_ids.filtered(
25-
lambda p: p.product_id.detailed_type == "product"
26-
)
27-
for subproduct in subproducts:
28-
subproduct_stock = subproduct.product_id
29-
sub_qty = subproduct.quantity
27+
28+
for line in pack.pack_line_ids.filtered(
29+
lambda p: p.product_id.type == "consu"
30+
):
31+
sub_qty = line.quantity
3032
if sub_qty:
3133
pack_qty_available.append(
32-
math.floor(subproduct_stock.qty_available / sub_qty)
34+
math.floor(
35+
(
36+
res[line.product_id.id]["qty_available"]
37+
- res[line.product_id.id]["outgoing_qty"]
38+
)
39+
/ sub_qty
40+
)
3341
)
3442
pack_virtual_available.append(
35-
math.floor(subproduct_stock.virtual_available / sub_qty)
43+
math.floor(
44+
res[line.product_id.id]["virtual_available"] / sub_qty
45+
)
3646
)
3747
pack_free_qty.append(
38-
math.floor(subproduct_stock.free_qty / sub_qty)
48+
math.floor(res[line.product_id.id]["free_qty"] / sub_qty)
3949
)
40-
res[product.id] = {
50+
res[pack.id] = {
4151
"qty_available": (pack_qty_available and min(pack_qty_available) or 0),
4252
"free_qty": (pack_free_qty and min(pack_free_qty) or 0),
4353
"incoming_qty": 0,
@@ -71,7 +81,7 @@ def _compute_quantities(self):
7181
service products if they are pack.
7282
"""
7383
service_pack_products = self.filtered(
74-
lambda p: p.detailed_type == "service" and p.pack_ok
84+
lambda p: p.type == "service" and p.pack_ok
7585
)
7686
result = super(
7787
ProductProduct, self - service_pack_products

Diff for: stock_product_pack/tests/test_stock_product_pack.py

+26-8
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,44 @@ def setUpClass(cls):
1717
category_all_id = cls.env.ref("product.product_category_all").id
1818
cls.product_obj = cls.env["product.product"]
1919
cls.stock_rule_obj = cls.env["stock.rule"]
20+
# The model stock doesn't add anymore the 'product'
21+
# selection to the product type.
22+
# Thus the type is changed to 'consu'
2023
component_1 = cls.product_obj.create(
2124
{
2225
"name": "Component 1",
23-
"detailed_type": "product",
26+
"type": "consu",
27+
"is_storable": True,
2428
"categ_id": category_all_id,
2529
}
2630
)
2731
component_2 = cls.product_obj.create(
2832
{
2933
"name": "Component 2",
30-
"detailed_type": "product",
34+
"type": "consu",
35+
"is_storable": True,
3136
"categ_id": category_all_id,
3237
}
3338
)
3439
component_3 = cls.product_obj.create(
3540
{
3641
"name": "Component 3",
37-
"detailed_type": "service",
42+
"type": "service",
3843
"categ_id": category_all_id,
3944
}
4045
)
4146
component_4 = cls.product_obj.create(
4247
{
4348
"name": "Component 4",
44-
"detailed_type": "consu",
49+
"type": "consu",
50+
"is_storable": True,
4551
"categ_id": category_all_id,
4652
}
4753
)
4854
cls.pack_dc = cls.product_obj.create(
4955
{
5056
"name": "Pack",
51-
"detailed_type": "product",
57+
"type": "consu",
5258
"pack_ok": True,
5359
"pack_type": "detailed",
5460
"pack_component_price": "detailed",
@@ -94,7 +100,7 @@ def setUpClass(cls):
94100
cls.pack_dc_with_dm = cls.product_obj.create(
95101
{
96102
"name": "Pack With storeable and not move product",
97-
"detailed_type": "product",
103+
"type": "consu",
98104
"pack_ok": True,
99105
"dont_create_move": True,
100106
"pack_type": "detailed",
@@ -161,6 +167,18 @@ def test_compute_quantities_dict(self):
161167
"location_dest_id": location_dest_id,
162168
},
163169
),
170+
(
171+
0,
172+
0,
173+
{
174+
"name": "incoming_move_test_03",
175+
"product_id": components[3].id,
176+
"product_uom_qty": 9,
177+
"product_uom": components[3].uom_id.id,
178+
"location_id": location_id,
179+
"location_dest_id": location_dest_id,
180+
},
181+
),
164182
],
165183
}
166184
)
@@ -186,7 +204,7 @@ def test_pack_with_dont_move_the_parent(self):
186204
def create_orderpoint(product, qty_min, qty_max, location, group):
187205
return self.env["stock.warehouse.orderpoint"].create(
188206
{
189-
"name": "OP/%s" % product.name,
207+
"name": f"OP/{product.name}",
190208
"product_id": product.id,
191209
"product_min_qty": qty_min,
192210
"product_max_qty": qty_max,
@@ -203,7 +221,7 @@ def create_orderpoint(product, qty_min, qty_max, location, group):
203221
self.env.ref("stock.stock_location_stock"),
204222
pg,
205223
)
206-
self.env["stock.scheduler.compute"].create({}).procure_calculation()
224+
# self.env["stock.scheduler.compute"].create({}).procure_calculation()
207225
picking_ids = self.env["stock.picking"].search([("group_id", "=", pg.id)])
208226
# we need to ensure that only the compents of the packs are in the moves.
209227
self.assertFalse(self.pack_dc_with_dm in picking_ids.move_ids.product_id)

Diff for: stock_product_pack/views/product_template_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<field name="pack_modifiable" position="after">
1212
<field
1313
name="dont_create_move"
14-
invisible="not pack_ok or detailed_type == 'service'"
14+
invisible="not pack_ok or type == 'service'"
1515
/>
1616
</field>
1717
</field>

0 commit comments

Comments
 (0)