1
1
# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
2
2
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
3
3
import odoo .tests .common as test_common
4
+ from odoo .tests .common import Form
4
5
5
6
6
7
class TestMaintenanceStock (test_common .TransactionCase ):
7
8
def setUp (self ):
8
9
super ().setUp ()
9
-
10
10
self .maintenance_warehouse = self .env ["stock.warehouse" ].create (
11
- {"name" : "Test warehouse" , "code" : "TEST" ,}
12
- {"name" : "Test warehouse" , "code" : "TEST" }
13
11
{
14
12
"name" : "Test warehouse" ,
15
13
"code" : "TEST" ,
@@ -30,6 +28,7 @@ def setUp(self):
30
28
{
31
29
"name" : "Test equipment" ,
32
30
"allow_consumptions" : True ,
31
+ "equipment_assign_to" : "employee" ,
33
32
"default_consumption_warehouse_id" : self .maintenance_warehouse .id ,
34
33
}
35
34
)
@@ -109,61 +108,26 @@ def test_request(self):
109
108
110
109
def test_picking (self ):
111
110
self .assertEqual (len (self .request_1 .stock_picking_ids ), 0 )
112
- self .assertEqual (len (self .equipment_1 .stock_picking_ids ), 0 )
113
-
114
- qty_done = 5.0
115
- move_line_data = {
116
- "product_id" : self .product1 .id ,
117
- "product_uom_id" : self .env .ref ("uom.product_uom_unit" ).id ,
118
- "qty_done" : qty_done ,
119
- "location_id" : self .maintenance_warehouse .lot_stock_id .id ,
120
- "location_dest_id" : self .maintenance_warehouse .wh_cons_loc_id .id ,
121
- }
122
- location_id = self .maintenance_warehouse .lot_stock_id .id
123
- location_dest_id = self .maintenance_warehouse .wh_cons_loc_id .id
124
- picking_type_id = self .maintenance_warehouse .cons_type_id .id
125
- picking = self .env ["stock.picking" ].create (
111
+ location_id = self .maintenance_warehouse .lot_stock_id
112
+ location_dest_id = self .maintenance_warehouse .wh_cons_loc_id
113
+ picking_type_id = self .maintenance_warehouse .cons_type_id
114
+ self .env ["stock.quant" ].create (
126
115
{
127
- "maintenance_request_id" : self .request_1 .id ,
128
- "picking_type_id" : picking_type_id ,
129
- "location_id" : location_id ,
130
- "location_dest_id" : location_dest_id ,
131
- "move_lines" : [
132
- (
133
- 0 ,
134
- 0 ,
135
- {
136
- "name" : "Test move" ,
137
- "product_id" : self .product1 .id ,
138
- "product_uom" : self .env .ref ("uom.product_uom_unit" ).id ,
139
- "product_uom_qty" : 5.0 ,
140
- "picking_type_id" : picking_type_id ,
141
- "location_id" : location_id ,
142
- "location_dest_id" : location_dest_id ,
143
- "move_line_ids" : [
144
- (
145
- 0 ,
146
- 0 ,
147
- {
148
- "product_id" : self .product1 .id ,
149
- "product_uom_id" : self .env .ref (
150
- "uom.product_uom_unit"
151
- ).id ,
152
- "qty_done" : qty_done ,
153
- "location_id" : location_id ,
154
- "location_dest_id" : location_dest_id ,
155
- },
156
- )
157
- ],
158
- },
159
- )
160
- ],
116
+ "product_id" : self .product1 .id ,
117
+ "location_id" : location_id .id ,
118
+ "quantity" : 5 ,
161
119
}
162
120
)
163
-
121
+ picking_form = Form (self .env ["stock.picking" ])
122
+ picking_form .picking_type_id = picking_type_id
123
+ picking_form .location_id = location_id
124
+ picking_form .location_dest_id = location_dest_id
125
+ with picking_form .move_ids_without_package .new () as move :
126
+ move .product_id = self .product1
127
+ move .product_uom_qty = 5.0
128
+ picking = picking_form .save ()
129
+ picking .write ({"maintenance_request_id" : self .request_1 .id })
164
130
self .assertEqual (len (self .request_1 .stock_picking_ids ), 1 )
165
- self .assertEqual (len (self .equipment_1 .stock_picking_ids ), 1 )
166
-
167
131
stock_quant_obj = self .env ["stock.quant" ]
168
132
domain_from = [
169
133
("product_id" , "=" , self .product1 .id ),
@@ -173,11 +137,12 @@ def test_picking(self):
173
137
("product_id" , "=" , self .product1 .id ),
174
138
("location_id" , "=" , self .maintenance_warehouse .wh_cons_loc_id .id ),
175
139
]
176
- self .assertEqual (stock_quant_obj .search (domain_from ).quantity , 0 )
140
+ self .assertEqual (stock_quant_obj .search (domain_from ).quantity , 5 )
177
141
self .assertEqual (stock_quant_obj .search (domain_to ).quantity , 0 )
178
142
179
143
picking .action_confirm ()
180
- picking .action_done ()
181
-
182
- self .assertEqual (stock_quant_obj .search (domain_from ).quantity , - qty_done )
183
- self .assertEqual (stock_quant_obj .search (domain_to ).quantity , qty_done )
144
+ picking .action_assign ()
145
+ picking .move_line_ids .write ({"qty_done" : 5.0 })
146
+ picking .button_validate ()
147
+ self .assertEqual (stock_quant_obj .search (domain_from ).quantity , 0 )
148
+ self .assertEqual (stock_quant_obj .search (domain_to ).quantity , 5 )
0 commit comments