11# © 2020 Solvos Consultoría Informática (<http://www.solvos.es>)
22# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
33import odoo .tests .common as test_common
4+ from odoo .tests .common import Form
45
56
67class TestMaintenanceStock (test_common .TransactionCase ):
78 def setUp (self ):
89 super ().setUp ()
9-
1010 self .maintenance_warehouse = self .env ["stock.warehouse" ].create (
11- {"name" : "Test warehouse" , "code" : "TEST" ,}
12- {"name" : "Test warehouse" , "code" : "TEST" }
1311 {
1412 "name" : "Test warehouse" ,
1513 "code" : "TEST" ,
@@ -30,6 +28,7 @@ def setUp(self):
3028 {
3129 "name" : "Test equipment" ,
3230 "allow_consumptions" : True ,
31+ "equipment_assign_to" : "employee" ,
3332 "default_consumption_warehouse_id" : self .maintenance_warehouse .id ,
3433 }
3534 )
@@ -109,61 +108,26 @@ def test_request(self):
109108
110109 def test_picking (self ):
111110 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 (
126115 {
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 ,
161119 }
162120 )
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 })
164130 self .assertEqual (len (self .request_1 .stock_picking_ids ), 1 )
165- self .assertEqual (len (self .equipment_1 .stock_picking_ids ), 1 )
166-
167131 stock_quant_obj = self .env ["stock.quant" ]
168132 domain_from = [
169133 ("product_id" , "=" , self .product1 .id ),
@@ -173,11 +137,12 @@ def test_picking(self):
173137 ("product_id" , "=" , self .product1 .id ),
174138 ("location_id" , "=" , self .maintenance_warehouse .wh_cons_loc_id .id ),
175139 ]
176- self .assertEqual (stock_quant_obj .search (domain_from ).quantity , 0 )
140+ self .assertEqual (stock_quant_obj .search (domain_from ).quantity , 5 )
177141 self .assertEqual (stock_quant_obj .search (domain_to ).quantity , 0 )
178142
179143 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