Skip to content

Commit a941394

Browse files
committed
[OU-ADD] stock: tests
1 parent 775d4fe commit a941394

File tree

3 files changed

+289
-0
lines changed

3 files changed

+289
-0
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
env = locals().get("env")
2+
# create two step pull route, procure a product with it
3+
intermediate_location = env["stock.location"].create(
4+
{
5+
"name": "Intermediate location",
6+
"usage": "internal",
7+
}
8+
)
9+
env["ir.model.data"]._update_xmlids(
10+
[
11+
{
12+
"xml_id": "openupgrade_test_stock.intermediate_pull_location",
13+
"record": intermediate_location,
14+
}
15+
]
16+
)
17+
two_step_route = env["stock.route"].create(
18+
{
19+
"name": "2 steps",
20+
"rule_ids": [
21+
(
22+
0,
23+
0,
24+
{
25+
"name": "Stock → Intermediate",
26+
"location_src_id": env.ref("stock.stock_location_stock").id,
27+
"location_dest_id": intermediate_location.id,
28+
"picking_type_id": env.ref("stock.picking_type_internal").id,
29+
"action": "pull",
30+
# 'location_dest_from_rule': True, # v18
31+
},
32+
),
33+
(
34+
0,
35+
0,
36+
{
37+
"name": "Intermediate → Customer",
38+
"location_src_id": intermediate_location.id,
39+
"location_dest_id": env.ref("stock.stock_location_customers").id,
40+
"picking_type_id": env.ref("stock.picking_type_internal").id,
41+
"procure_method": "make_to_order",
42+
"action": "pull",
43+
# 'location_dest_from_rule': True, # v18
44+
},
45+
),
46+
],
47+
}
48+
)
49+
product = env["product.product"].create(
50+
{
51+
"name": "2 step product (pull)",
52+
"type": "product",
53+
# 'type': 'consu', # v18
54+
"route_ids": [(6, 0, two_step_route.ids)],
55+
}
56+
)
57+
env["ir.model.data"]._update_xmlids(
58+
[{"xml_id": "openupgrade_test_stock.pull_product", "record": product}]
59+
)
60+
procurement_group = env["procurement.group"].create(
61+
{
62+
"name": "2 step procurement",
63+
}
64+
)
65+
env["procurement.group"].run(
66+
[
67+
env["procurement.group"].Procurement(
68+
product_id=product,
69+
product_qty=42,
70+
product_uom=product.uom_id,
71+
location_id=env.ref("stock.stock_location_customers"),
72+
name="2 step procurement",
73+
origin="/",
74+
company_id=env.company,
75+
values={"group_id": procurement_group},
76+
),
77+
]
78+
)
79+
env.cr.commit()
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
env = locals().get("env")
2+
# create two step push route, move a product there
3+
intermediate_location = env["stock.location"].create(
4+
{
5+
"name": "Intermediate location",
6+
"usage": "internal",
7+
}
8+
)
9+
env["ir.model.data"]._update_xmlids(
10+
[
11+
{
12+
"xml_id": "openupgrade_test_stock.intermediate_push_location",
13+
"record": intermediate_location,
14+
}
15+
]
16+
)
17+
two_step_route = env["stock.route"].create(
18+
{
19+
"name": "2 steps",
20+
"rule_ids": [
21+
(
22+
0,
23+
0,
24+
{
25+
"name": "Stock → Intermediate",
26+
"location_src_id": env.ref("stock.stock_location_stock").id,
27+
"location_dest_id": intermediate_location.id,
28+
"picking_type_id": env.ref("stock.picking_type_internal").id,
29+
"action": "push",
30+
},
31+
),
32+
(
33+
0,
34+
0,
35+
{
36+
"name": "Intermediate → Customer",
37+
"location_src_id": intermediate_location.id,
38+
"location_dest_id": env.ref("stock.stock_location_customers").id,
39+
"picking_type_id": env.ref("stock.picking_type_out").id,
40+
"action": "push",
41+
},
42+
),
43+
],
44+
}
45+
)
46+
product = env["product.product"].create(
47+
{
48+
"name": "2 step product (push)",
49+
"type": "product",
50+
# 'type': 'consu', # v18
51+
"route_ids": [(6, 0, two_step_route.ids)],
52+
}
53+
)
54+
env["ir.model.data"]._update_xmlids(
55+
[{"xml_id": "openupgrade_test_stock.push_product", "record": product}]
56+
)
57+
in_move = env["stock.move"].create(
58+
{
59+
"name": "in",
60+
"location_id": env.ref("stock.stock_location_suppliers").id,
61+
"location_dest_id": env.ref("stock.stock_location_stock").id,
62+
# 'location_final_id': env.ref('stock.stock_location_customers').id,
63+
"route_ids": [(6, 0, two_step_route.ids)],
64+
"product_id": product.id,
65+
"quantity": 42,
66+
"product_uom_qty": 42,
67+
"picked": True,
68+
}
69+
)
70+
in_move._action_done()
71+
in_move.move_dest_ids._action_done()
72+
env.cr.commit()
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
from odoo.tests import TransactionCase
2+
3+
from odoo.addons.openupgrade_framework import openupgrade_test
4+
5+
6+
@openupgrade_test
7+
class TestStockMigration(TransactionCase):
8+
def test_picking_type_required_fields(self):
9+
"""Test that newly required fields are set"""
10+
# TODO: this fails with demo data
11+
for picking_type in self.env["stock.picking.type"].search([]):
12+
self.assertTrue(picking_type.default_location_src_id)
13+
self.assertTrue(picking_type.default_location_dest_id)
14+
15+
def test_pull_moves(self):
16+
"""
17+
Test that pull moves have been migrated correctly and new moves yield the
18+
same result
19+
"""
20+
product = self.env.ref("openupgrade_test_stock.pull_product")
21+
stock_location = self.env.ref("stock.stock_location_stock")
22+
intermediate_location = self.env.ref(
23+
"openupgrade_test_stock.intermediate_pull_location"
24+
)
25+
customer_location = self.env.ref("stock.stock_location_customers")
26+
27+
moves = self.env["stock.move"].search([("product_id", "=", product.id)])
28+
from_stock = moves.filtered(lambda x: x.location_id == stock_location)
29+
from_intermediate = moves.filtered(
30+
lambda x: x.location_id == intermediate_location
31+
)
32+
33+
self.assertEqual(from_stock.location_dest_id, intermediate_location)
34+
self.assertEqual(from_stock.location_final_id, intermediate_location)
35+
36+
self.assertEqual(from_intermediate.location_dest_id, customer_location)
37+
self.assertEqual(from_intermediate.location_final_id, customer_location)
38+
39+
# TODO: this should be done by migration
40+
self.env["stock.rule"].search(
41+
[
42+
"|",
43+
("location_src_id", "=", intermediate_location.id),
44+
("location_dest_id", "=", intermediate_location.id),
45+
]
46+
).location_dest_from_rule = True
47+
48+
procurement_group = self.env["procurement.group"].create(
49+
{
50+
"name": "2 step procurement v18",
51+
}
52+
)
53+
self.env["procurement.group"].run(
54+
[
55+
self.env["procurement.group"].Procurement(
56+
product_id=product,
57+
product_qty=42,
58+
product_uom=product.uom_id,
59+
location_id=self.env.ref("stock.stock_location_customers"),
60+
name="2 step procurement",
61+
origin="/",
62+
company_id=self.env.company,
63+
values={"group_id": procurement_group},
64+
),
65+
]
66+
)
67+
68+
new_moves = (
69+
self.env["stock.move"].search([("product_id", "=", product.id)]) - moves
70+
)
71+
from_stock = new_moves.filtered(lambda x: x.location_id == stock_location)
72+
from_intermediate = new_moves.filtered(
73+
lambda x: x.location_id == intermediate_location
74+
)
75+
76+
self.assertEqual(from_stock.location_dest_id, intermediate_location)
77+
self.assertEqual(from_stock.location_final_id, intermediate_location)
78+
79+
self.assertEqual(from_intermediate.location_dest_id, customer_location)
80+
self.assertEqual(from_intermediate.location_final_id, customer_location)
81+
82+
def test_push_moves(self):
83+
"""
84+
Test that push moves have been migrated correctly and new moves yield the
85+
same result
86+
"""
87+
product = self.env.ref("openupgrade_test_stock.push_product")
88+
stock_location = self.env.ref("stock.stock_location_stock")
89+
intermediate_location = self.env.ref(
90+
"openupgrade_test_stock.intermediate_push_location"
91+
)
92+
customer_location = self.env.ref("stock.stock_location_customers")
93+
94+
moves = self.env["stock.move"].search([("product_id", "=", product.id)])
95+
96+
from_stock = moves.filtered(lambda x: x.location_id == stock_location)
97+
from_intermediate = moves.filtered(
98+
lambda x: x.location_id == intermediate_location
99+
)
100+
101+
self.assertEqual(from_stock.location_dest_id, intermediate_location)
102+
# TODO: this fails because we don't set this from move_dest_ids/route_ids
103+
self.assertEqual(from_stock.location_final_id, customer_location)
104+
105+
self.assertEqual(from_intermediate.location_dest_id, customer_location)
106+
self.assertEqual(from_intermediate.location_final_id, customer_location)
107+
108+
in_move = self.env["stock.move"].create(
109+
{
110+
"name": "in",
111+
"location_id": self.env.ref("stock.stock_location_suppliers").id,
112+
"location_dest_id": stock_location.id,
113+
"location_final_id": customer_location.id,
114+
"route_ids": [(6, 0, moves.route_ids.ids)],
115+
"product_id": product.id,
116+
"quantity": 42,
117+
"product_uom_qty": 42,
118+
"picked": True,
119+
}
120+
)
121+
in_move._action_done()
122+
in_move.move_dest_ids.picked = True
123+
in_move.move_dest_ids._action_done()
124+
125+
new_moves = (
126+
self.env["stock.move"].search([("product_id", "=", product.id)]) - moves
127+
)
128+
129+
from_stock = new_moves.filtered(lambda x: x.location_id == stock_location)
130+
from_intermediate = new_moves.filtered(
131+
lambda x: x.location_id == intermediate_location
132+
)
133+
134+
self.assertEqual(from_stock.location_dest_id, intermediate_location)
135+
self.assertEqual(from_stock.location_final_id, customer_location)
136+
137+
self.assertEqual(from_intermediate.location_dest_id, customer_location)
138+
self.assertEqual(from_intermediate.location_final_id, customer_location)

0 commit comments

Comments
 (0)