@@ -9,84 +9,74 @@ class TestStockQuantManualAssign(TransactionCase):
9
9
@classmethod
10
10
def setUpClass (cls ):
11
11
super ().setUpClass ()
12
- cls .env = cls .env (context = dict (cls .env .context , tracking_disable = True ))
13
- cls .quant_model = cls .env ["stock.quant" ]
14
- cls .picking_model = cls .env ["stock.picking" ]
15
- cls .location_model = cls .env ["stock.location" ]
16
- cls .move_model = cls .env ["stock.move" ]
17
12
cls .quant_assign_wizard = cls .env ["assign.manual.quants" ]
18
- cls .ModelDataObj = cls .env ["ir.model.data" ]
19
13
cls .product = cls .env ["product.product" ].create (
20
14
{"name" : "Product 4 test" , "type" : "product" }
21
15
)
22
16
cls .location_src = cls .env .ref ("stock.stock_location_locations_virtual" )
23
17
cls .location_dst = cls .env .ref ("stock.stock_location_customers" )
24
- cls .picking_type_out = cls .ModelDataObj ._xmlid_to_res_id (
18
+ cls .picking_type_out = cls .env [ "ir.model.data" ] ._xmlid_to_res_id (
25
19
"stock.picking_type_out"
26
20
)
27
21
cls .env ["stock.picking.type" ].browse (
28
22
cls .picking_type_out
29
23
).reservation_method = "manual"
30
- cls .location1 = cls .location_model .create (
31
- {
32
- "name" : "Location 1" ,
33
- "usage" : "internal" ,
34
- "location_id" : cls .location_src .id ,
35
- }
36
- )
37
- cls .location2 = cls .location_model .create (
38
- {
39
- "name" : "Location 2" ,
40
- "usage" : "internal" ,
41
- "location_id" : cls .location_src .id ,
42
- }
43
- )
44
- cls .location3 = cls .location_model .create (
45
- {
46
- "name" : "Location 3" ,
47
- "usage" : "internal" ,
48
- "location_id" : cls .location_src .id ,
49
- }
50
- )
24
+ cls .location1 = cls ._create_location (cls , "Location 1" )
25
+ cls .location2 = cls ._create_location (cls , "Location 2" )
26
+ cls .location3 = cls ._create_location (cls , "Location 3" )
51
27
cls .picking_type = cls .env .ref ("stock.picking_type_out" )
52
- cls .quant1 = cls .quant_model .sudo ().create (
28
+ cls .quant1 = cls ._create_quant (cls , cls .product , 100.0 , cls .location1 )
29
+ cls .quant2 = cls ._create_quant (cls , cls .product , 100.0 , cls .location2 )
30
+ cls .quant3 = cls ._create_quant (cls , cls .product , 100.0 , cls .location3 )
31
+ cls .picking = cls .env ["stock.picking" ].create (
53
32
{
54
- "product_id" : cls .product .id ,
55
- "quantity" : 100.0 ,
33
+ "picking_type_id" : cls .picking_type .id ,
56
34
"location_id" : cls .location1 .id ,
35
+ "location_dest_id" : cls .location_dst .id ,
57
36
}
58
37
)
59
- cls .quant2 = cls .quant_model .sudo ().create (
60
- {
61
- "product_id" : cls .product .id ,
62
- "quantity" : 100.0 ,
63
- "location_id" : cls .location2 .id ,
64
- }
65
- )
66
- cls .quant3 = cls .quant_model .sudo ().create (
67
- {
68
- "product_id" : cls .product .id ,
69
- "quantity" : 100.0 ,
70
- "location_id" : cls .location3 .id ,
71
- }
72
- )
73
- cls .move = cls .move_model .create (
38
+ cls .move = cls .env ["stock.move" ].create (
74
39
{
75
40
"name" : cls .product .name ,
76
41
"product_id" : cls .product .id ,
77
42
"product_uom_qty" : 400.0 ,
78
43
"product_uom" : cls .product .uom_id .id ,
79
44
"location_id" : cls .location_src .id ,
80
45
"location_dest_id" : cls .location_dst .id ,
81
- "picking_type_id " : cls .picking_type .id ,
46
+ "picking_id " : cls .picking .id ,
82
47
}
83
48
)
84
49
cls .move ._action_confirm ()
85
50
86
- def test_quant_assign_wizard (self ):
87
- wizard = self .quant_assign_wizard .with_context (active_id = self .move .id ).create (
88
- {}
51
+ def _create_location (self , name ):
52
+ return self .env ["stock.location" ].create (
53
+ {"name" : name , "usage" : "internal" , "location_id" : self .location_src .id }
54
+ )
55
+
56
+ def _create_quant (self , product , qty , location ):
57
+ return (
58
+ self .env ["stock.quant" ]
59
+ .sudo ()
60
+ .create (
61
+ {"product_id" : product .id , "quantity" : qty , "location_id" : location .id }
62
+ )
63
+ )
64
+
65
+ def _create_wizard (self ):
66
+ return (
67
+ self .env ["assign.manual.quants" ]
68
+ .with_context (active_id = self .move .id )
69
+ .create ({})
89
70
)
71
+
72
+ def _process_basic_manual_assign_steps (self , wizard ):
73
+ wizard .quants_lines [0 ].write ({"selected" : True })
74
+ wizard .quants_lines [0 ]._onchange_selected ()
75
+ wizard .quants_lines [1 ].write ({"selected" : True , "qty" : 50.0 })
76
+ self .assertEqual (wizard .lines_qty , 150.0 )
77
+
78
+ def test_quant_assign_wizard (self ):
79
+ wizard = self ._create_wizard ()
90
80
self .assertEqual (
91
81
len (wizard .quants_lines .ids ),
92
82
3 ,
@@ -105,9 +95,7 @@ def test_quant_assign_wizard(self):
105
95
self .assertEqual (wizard .move_qty , self .move .product_uom_qty )
106
96
107
97
def test_quant_assign_wizard_constraint (self ):
108
- wizard = self .quant_assign_wizard .with_context (active_id = self .move .id ).create (
109
- {}
110
- )
98
+ wizard = self ._create_wizard ()
111
99
self .assertEqual (
112
100
len (wizard .quants_lines .ids ),
113
101
3 ,
@@ -129,31 +117,42 @@ def test_quant_assign_wizard_constraint(self):
129
117
)
130
118
131
119
def test_quant_manual_assign (self ):
132
- wizard = self .quant_assign_wizard .with_context (active_id = self .move .id ).create (
133
- {}
134
- )
120
+ wizard = self ._create_wizard ()
135
121
self .assertEqual (
136
122
len (wizard .quants_lines .ids ),
137
123
3 ,
138
124
"Three quants created, three quants got by default" ,
139
125
)
140
- wizard .quants_lines [0 ].write ({"selected" : True })
141
- wizard .quants_lines [0 ]._onchange_selected ()
142
- wizard .quants_lines [1 ].write ({"selected" : True , "qty" : 50.0 })
143
- self .assertEqual (wizard .lines_qty , 150.0 )
126
+ self ._process_basic_manual_assign_steps (wizard )
144
127
self .assertEqual (wizard .move_qty , 250.0 )
145
128
wizard .assign_quants ()
146
129
self .assertAlmostEqual (
147
130
len (self .move .move_line_ids ),
148
131
2 ,
149
132
"There are 2 quants selected" ,
150
133
)
134
+ self .assertFalse (self .move .picking_type_id .auto_fill_qty_done )
135
+ self .assertEqual (sum (self .move .move_line_ids .mapped ("qty_done" )), 0.0 )
136
+
137
+ def _process_quant_manual_assign_auto_fill_qty_done (self ):
138
+ wizard = self ._create_wizard ()
139
+ self ._process_basic_manual_assign_steps (wizard )
140
+ self .picking_type .auto_fill_qty_done = True
141
+ wizard .assign_quants ()
142
+ self .assertTrue (self .move .picking_type_id .auto_fill_qty_done )
143
+ self .assertEqual (sum (self .move .move_line_ids .mapped ("qty_done" )), 150.0 )
144
+
145
+ def test_quant_manual_assign_auto_fill_qty_done_planned (self ):
146
+ self .assertFalse (self .picking .immediate_transfer )
147
+ self ._process_quant_manual_assign_auto_fill_qty_done ()
148
+
149
+ def test_quant_manual_assign_auto_fill_qty_done_immediate (self ):
150
+ self .picking .immediate_transfer = True
151
+ self ._process_quant_manual_assign_auto_fill_qty_done ()
151
152
152
153
def test_quant_assign_wizard_after_availability_check (self ):
153
154
self .move ._action_assign ()
154
- wizard = self .quant_assign_wizard .with_context (active_id = self .move .id ).create (
155
- {}
156
- )
155
+ wizard = self ._create_wizard ()
157
156
self .assertEqual (
158
157
len (wizard .quants_lines .ids ),
159
158
3 ,
0 commit comments