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
11
{
12
12
"name" : "Test warehouse" ,
@@ -28,6 +28,7 @@ def setUp(self):
28
28
{
29
29
"name" : "Test equipment" ,
30
30
"allow_consumptions" : True ,
31
+ "equipment_assign_to" : "employee" ,
31
32
"default_consumption_warehouse_id" : self .maintenance_warehouse .id ,
32
33
}
33
34
)
@@ -107,54 +108,26 @@ def test_request(self):
107
108
108
109
def test_picking (self ):
109
110
self .assertEqual (len (self .request_1 .stock_picking_ids ), 0 )
110
- self .assertEqual (len (self .equipment_1 .stock_picking_ids ), 0 )
111
-
112
- qty_done = 5.0
113
- location_id = self .maintenance_warehouse .lot_stock_id .id
114
- location_dest_id = self .maintenance_warehouse .wh_cons_loc_id .id
115
- picking_type_id = self .maintenance_warehouse .cons_type_id .id
116
- 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 (
117
115
{
118
- "maintenance_request_id" : self .request_1 .id ,
119
- "picking_type_id" : picking_type_id ,
120
- "location_id" : location_id ,
121
- "location_dest_id" : location_dest_id ,
122
- "move_lines" : [
123
- (
124
- 0 ,
125
- 0 ,
126
- {
127
- "name" : "Test move" ,
128
- "product_id" : self .product1 .id ,
129
- "product_uom" : self .env .ref ("uom.product_uom_unit" ).id ,
130
- "product_uom_qty" : 5.0 ,
131
- "picking_type_id" : picking_type_id ,
132
- "location_id" : location_id ,
133
- "location_dest_id" : location_dest_id ,
134
- "move_line_ids" : [
135
- (
136
- 0 ,
137
- 0 ,
138
- {
139
- "product_id" : self .product1 .id ,
140
- "product_uom_id" : self .env .ref (
141
- "uom.product_uom_unit"
142
- ).id ,
143
- "qty_done" : qty_done ,
144
- "location_id" : location_id ,
145
- "location_dest_id" : location_dest_id ,
146
- },
147
- )
148
- ],
149
- },
150
- )
151
- ],
116
+ "product_id" : self .product1 .id ,
117
+ "location_id" : location_id .id ,
118
+ "quantity" : 5 ,
152
119
}
153
120
)
154
-
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 })
155
130
self .assertEqual (len (self .request_1 .stock_picking_ids ), 1 )
156
- self .assertEqual (len (self .equipment_1 .stock_picking_ids ), 1 )
157
-
158
131
stock_quant_obj = self .env ["stock.quant" ]
159
132
domain_from = [
160
133
("product_id" , "=" , self .product1 .id ),
@@ -164,11 +137,12 @@ def test_picking(self):
164
137
("product_id" , "=" , self .product1 .id ),
165
138
("location_id" , "=" , self .maintenance_warehouse .wh_cons_loc_id .id ),
166
139
]
167
- self .assertEqual (stock_quant_obj .search (domain_from ).quantity , 0 )
140
+ self .assertEqual (stock_quant_obj .search (domain_from ).quantity , 5 )
168
141
self .assertEqual (stock_quant_obj .search (domain_to ).quantity , 0 )
169
142
170
143
picking .action_confirm ()
171
- picking .action_done ()
172
-
173
- self .assertEqual (stock_quant_obj .search (domain_from ).quantity , - qty_done )
174
- 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