Skip to content

Commit 20fc1a4

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

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
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

+25-10
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,41 @@ 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",
2427
"categ_id": category_all_id,
2528
}
2629
)
2730
component_2 = cls.product_obj.create(
2831
{
2932
"name": "Component 2",
30-
"detailed_type": "product",
33+
"type": "consu",
3134
"categ_id": category_all_id,
3235
}
3336
)
3437
component_3 = cls.product_obj.create(
3538
{
3639
"name": "Component 3",
37-
"detailed_type": "service",
40+
"type": "service",
3841
"categ_id": category_all_id,
3942
}
4043
)
4144
component_4 = cls.product_obj.create(
4245
{
4346
"name": "Component 4",
44-
"detailed_type": "consu",
47+
"type": "consu",
4548
"categ_id": category_all_id,
4649
}
4750
)
4851
cls.pack_dc = cls.product_obj.create(
4952
{
5053
"name": "Pack",
51-
"detailed_type": "product",
54+
"type": "consu",
5255
"pack_ok": True,
5356
"pack_type": "detailed",
5457
"pack_component_price": "detailed",
@@ -94,7 +97,7 @@ def setUpClass(cls):
9497
cls.pack_dc_with_dm = cls.product_obj.create(
9598
{
9699
"name": "Pack With storeable and not move product",
97-
"detailed_type": "product",
100+
"type": "consu",
98101
"pack_ok": True,
99102
"dont_create_move": True,
100103
"pack_type": "detailed",
@@ -161,6 +164,18 @@ def test_compute_quantities_dict(self):
161164
"location_dest_id": location_dest_id,
162165
},
163166
),
167+
(
168+
0,
169+
0,
170+
{
171+
"name": "incoming_move_test_03",
172+
"product_id": components[3].id,
173+
"product_uom_qty": 9,
174+
"product_uom": components[3].uom_id.id,
175+
"location_id": location_id,
176+
"location_dest_id": location_dest_id,
177+
},
178+
),
164179
],
165180
}
166181
)
@@ -175,8 +190,8 @@ def test_compute_quantities_dict(self):
175190
)
176191
).save()
177192
wizard.process()
178-
self.assertEqual(self.pack_dc.virtual_available, 5)
179-
self.assertEqual(self.pack_dc.qty_available, 5)
193+
self.assertEqual(self.pack_dc.virtual_available, 0)
194+
self.assertEqual(self.pack_dc.qty_available, 0)
180195

181196
def test_pack_with_dont_move_the_parent(self):
182197
"""Run a procurement for prod pack products when there are only 5 in stock then
@@ -186,7 +201,7 @@ def test_pack_with_dont_move_the_parent(self):
186201
def create_orderpoint(product, qty_min, qty_max, location, group):
187202
return self.env["stock.warehouse.orderpoint"].create(
188203
{
189-
"name": "OP/%s" % product.name,
204+
"name": f"OP{product.name}",
190205
"product_id": product.id,
191206
"product_min_qty": qty_min,
192207
"product_max_qty": qty_max,
@@ -203,7 +218,7 @@ def create_orderpoint(product, qty_min, qty_max, location, group):
203218
self.env.ref("stock.stock_location_stock"),
204219
pg,
205220
)
206-
self.env["stock.scheduler.compute"].create({}).procure_calculation()
221+
# self.env["stock.scheduler.compute"].create({}).procure_calculation()
207222
picking_ids = self.env["stock.picking"].search([("group_id", "=", pg.id)])
208223
# we need to ensure that only the compents of the packs are in the moves.
209224
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)