flectra/addons/stock/test/wiseoperator.yml

159 lines
6.0 KiB
YAML
Raw Normal View History

-
Create a new stockable product
-
!record {model: product.product, id: product_wise}:
name: Wise Unit
type: product
categ_id: product.product_category_1
uom_id: product.product_uom_unit
uom_po_id: product.product_uom_unit
-
Create an incoming picking for this product of 10 PCE from suppliers to stock
-
!record {model: stock.picking, id: pick1_wise}:
name: Incoming picking (wise unit)
partner_id: base.res_partner_2
picking_type_id: picking_type_in
move_lines:
- product_id: product_wise
product_uom_qty: 10.00
location_id: stock_location_suppliers
location_dest_id: stock_location_stock
-
Confirm and assign picking and prepare partial
-
!python {model: stock.picking, id: pick1_wise}: |
self.action_confirm()
self.action_assign()
-
Put 4 pieces in shelf1 and 6 pieces in shelf2
-
!python {model: stock.picking, id: pick1_wise}: |
stock_pack = self.env['stock.move.line']
stock_quant_pack = self.env['stock.quant.package']
package1 = stock_quant_pack.create({'name': 'Pack 1'})
self.move_line_ids[0].write({
'result_package_id': package1.id,
'qty_done': 4,
'location_dest_id': ref('stock_location_components')
})
new_pack1 = stock_pack.create({
'product_id': ref('product_wise'),
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick1_wise'),
'qty_done': 6.0,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_14')
})
-
Transfer the receipt
-
!python {model: stock.picking, id: pick1_wise}: |
self.do_transfer()
-
Check the system created 3 quants
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product_wise'))])
assert len(records.ids) == 3, "The number of quants created is not correct"
-
Make a delivery order of 5 pieces to the customer
-
!record {model: stock.picking, id: delivery_order_wise1}:
name: outgoing picking 1 (wise unit)
partner_id: base.res_partner_4
picking_type_id: stock.picking_type_out
move_lines:
- product_id: product_wise
product_uom_qty: 5.0
location_id: stock_location_stock
location_dest_id: stock_location_customers
-
Assign and confirm
-
!python {model: stock.picking, id: delivery_order_wise1}: |
self.action_confirm()
self.action_assign()
assert self.state == 'assigned'
-
Make a delivery order of 5 pieces to the customer
-
!record {model: stock.picking, id: delivery_order_wise2}:
name: outgoing picking 2 (wise unit)
partner_id: base.res_partner_4
picking_type_id: stock.picking_type_out
move_lines:
- product_id: product_wise
product_uom_qty: 5.0
location_id: stock_location_stock
location_dest_id: stock_location_customers
-
Assign and confirm
-
!python {model: stock.picking, id: delivery_order_wise2}: |
self.action_confirm()
self.action_assign()
assert self.state == 'assigned'
-
2018-01-16 11:34:37 +01:00
The operator is a wise guy and decides to do the opposite of what Flectra proposes. He uses the products reserved on picking 1 on picking 2 and vice versa
-
!python {model: stock.picking, id: False}: |
picking1 = self.browse(ref('delivery_order_wise1'))
picking2 = self.browse(ref('delivery_order_wise2'))
move1 = picking1.move_lines[0]
move2 = picking2.move_lines[0]
pack_ids1 = picking1.move_line_ids
pack_ids2 = picking2.move_line_ids
assert pack_ids1.location_id.id == ref('stock_location_14')
assert set(pack_ids2.mapped('location_id.id')) == set([ref('stock_location_components'), ref('stock_location_14')])
# put the move lines from picking2 into picking1
for pack_id2 in pack_ids2:
new_pack_id1 = pack_id2.copy(default={'picking_id': picking1.id, 'move_id': move1.id})
new_pack_id1.qty_done = new_pack_id1.product_qty
new_pack_id1.with_context(bypass_reservation_update=True).product_uom_qty = 0
new_move_lines = picking1.move_line_ids.filtered(lambda p: p.qty_done)
assert sum(new_move_lines.mapped('product_qty')) == 0
assert sum(new_move_lines.mapped('qty_done')) == 5
assert set(new_move_lines.mapped('location_id.id')) == set([ref('stock_location_components'), ref('stock_location_14')])
# put the move line from picking1 into picking2
new_pack_id2 = pack_ids1.copy(default={'picking_id': picking2.id, 'move_id': move2.id})
new_pack_id2.qty_done = new_pack_id2.product_qty
new_pack_id2.with_context(bypass_reservation_update=True).product_uom_qty = 0
new_move_lines = picking2.move_line_ids.filtered(lambda p: p.qty_done)
assert len(new_move_lines) == 1
assert sum(new_move_lines.mapped('product_qty')) == 0
assert sum(new_move_lines.mapped('qty_done')) == 5
assert new_move_lines.location_id.id == ref('stock_location_14')
-
Process this picking
-
!python {model: stock.picking, id: delivery_order_wise1}: |
self.do_transfer()
-
Check there was no negative quant created by this picking
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product_wise')), ('quantity', '<', 0.0), ('location_id.id', '=',
ref('stock_location_stock'))])
assert len(records.ids) == 0, 'This should not have created a negative quant'
-
Check the other delivery order has changed its state back to ready
-
!python {model: stock.picking, id: delivery_order_wise2}: |
assert self.state == 'assigned', "Delivery order 2 should be back in ready state"
-
Process the second picking
-
!python {model: stock.picking, id: delivery_order_wise2}: |
self.action_done()
-
Check all quants are in Customers and there are no negative quants anymore
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product_wise')), ('location_id', '!=', ref('stock_location_suppliers'))])
assert all([x.location_id.id==ref('stock_location_customers') and x.quantity > 0.0 for x in records]), "Negative quant or wrong location detected"