flectra/addons/stock/test/packing.yml

174 lines
6.8 KiB
YAML
Raw Permalink Normal View History

-
Create a new stockable product
-
!record {model: product.product, id: product1, view: False}:
name: Nice product
type: product
categ_id: product.product_category_1
list_price: 100.0
standard_price: 70.0
seller_ids:
- delay: 1
name: base.res_partner_2
min_qty: 2.0
uom_id: product.product_uom_unit
uom_po_id: product.product_uom_unit
-
Create an incoming picking for this product of 300 PCE from suppliers to stock
-
!record {model: stock.picking, id: pick1}:
name: Incoming picking
partner_id: base.res_partner_2
picking_type_id: picking_type_in
move_lines:
- product_id: product1
product_uom_qty: 300.00
location_id: stock_location_suppliers
location_dest_id: stock_location_stock
-
Confirm and assign picking
-
!python {model: stock.picking, id: pick1}: |
self.action_confirm()
self.action_assign()
-
Put 120 pieces on Pallet 1 (package), 120 pieces on Pallet 2 with lot A and 60 pieces on Pallet 3
-
!python {model: stock.picking, id: pick1}: |
#Change quantity of first to 120 and create 2 others quant operations
stock_pack = self.env['stock.move.line']
stock_quant_pack = self.env['stock.quant.package']
#create lot A
lot_a = self.env['stock.production.lot'].create({'name': 'Lot A', 'product_id': ref('product1')})
#create package
package1 = stock_quant_pack.create({'name': 'Pallet 1'})
package2 = stock_quant_pack.create({'name': 'Pallet 2'})
package3 = stock_quant_pack.create({'name': 'Pallet 3'})
#Create package for each line and assign it as result_package_id
#create pack operation
self.move_line_ids[0].write({'result_package_id': package1.id, 'qty_done': 120})
new_pack1 = stock_pack.create({
'product_id': ref('product1'),
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick1'),
'lot_id': lot_a.id,
'qty_done': 120,
'result_package_id': package2.id,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_stock')
})
new_pack2 = stock_pack.create({
'product_id': ref('product1'),
'product_uom_id': ref('product.product_uom_unit'),
'picking_id': ref('pick1'),
'result_package_id': package3.id,
'qty_done': 60,
'location_id': ref('stock_location_suppliers'),
'location_dest_id': ref('stock_location_stock')
})
-
Transfer the receipt
-
!python {model: stock.picking, id: pick1}: |
self.action_done()
-
Check the system created 5 quants one with 120 pieces on pallet 1, one with 120 pieces on pallet 2 with lot A and 60 pieces on pallet 3 in stock
and 1 with -180 pieces and another with -120 piece lot A in supplier
-
!python {model: stock.quant, id: False}: |
quants = self.search([('product_id','=',ref('product1'))])
assert len(quants.ids) == 5, "The number of quants created is not correct"
for quant in quants:
if quant.package_id.name == 'Pallet 1':
assert quant.quantity == 120, "Should have 120 pieces on pallet 1"
elif quant.package_id.name == 'Pallet 2':
assert quant.quantity == 120, "Should have 120 pieces on pallet 2"
elif quant.package_id.name == 'Pallet 3':
assert quant.quantity == 60, "Should have 60 pieces on pallet 3"
-
Check there is no backorder or extra moves created
-
!python {model: stock.picking, id: pick1}: |
backorder = self.search([('backorder_id', '=', ref('pick1'))])
assert not backorder, ""
#Check extra moves created
assert len(self.move_lines) == 1, ""
-
Make a delivery order of 300 pieces to the customer
-
!record {model: stock.picking, id: delivery_order1}:
name: outgoing picking
partner_id: base.res_partner_4
picking_type_id: stock.picking_type_out
move_lines:
- product_id: product1
product_uom_qty: 300.00
location_id: stock_location_stock
location_dest_id: stock_location_customers
-
Assign and confirm
-
!python {model: stock.picking, id: delivery_order1}: |
self.action_confirm()
self.action_assign()
-
Instead of doing the 300 pieces, you decide to take pallet 1 (do not mention product in operation here) and 20 pieces from lot A and 10 pieces from pallet 3
-
!python {model: stock.picking, id: delivery_order1}: |
for rec in self.move_line_ids:
if rec.package_id.name == 'Pallet 1':
rec.qty_done = 120
rec.result_package_id = False
if rec.package_id.name == 'Pallet 2':
rec.qty_done = 20
rec.result_package_id = False
if rec.package_id.name == 'Pallet 3':
rec.qty_done = 10
rec.result_package_id = False
-
Process this picking
-
!python {model: stock.picking, id: delivery_order1 }: |
self.action_done()
-
Check the quants that you have 100 pieces of pallet 2 and 50 pieces of pallet 3 in stock
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product1'))])
for rec in records:
if rec.package_id.name == 'Pallet 2' and rec.location_id.id == ref('stock_location_stock'):
assert rec.quantity == 100, "Should have 100 pieces in stock on pallet 2, got " + str(rec.quantity)
elif rec.package_id.name == 'Pallet 3' and rec.location_id.id == ref('stock_location_stock'):
assert rec.quantity == 50, "Should have 50 pieces in stock on pallet 3"
else:
assert rec.location_id.id != ref('stock_location_stock'), "Unrecognized quant in stock"
-
Check a backorder was created and on that backorder, prepare partial and process backorder
-
!python {model: stock.picking, id: False}: |
backorders = self.search([('backorder_id', '=', ref('delivery_order1'))])
assert backorders, "Backorder should have been created"
backorders.action_assign()
picking = backorders[0]
assert len(picking.move_line_ids) == 2, "Wrong number of pack operation"
for pack_op in picking.move_line_ids:
assert pack_op.package_id.name in ('Pallet 2', 'Pallet 3'), "Wrong pallet info in pack operation (%s found)" % (pack_op.package_id.name)
if pack_op.package_id.name == 'Pallet 2':
assert pack_op.product_qty == 100
pack_op.qty_done = 100
elif pack_op.package_id.name == 'Pallet 3':
assert pack_op.product_qty == 50
pack_op.qty_done = 50
backorders.action_done()
-
Check there are still 0 pieces in stock
-
!python {model: stock.quant, id: False}: |
records = self.search([('product_id','=',ref('product1')), ('location_id', '=', ref('stock_location_stock'))])
total_qty = 0
for rec in records:
total_qty += rec.quantity
product = self.env["product.product"].browse(ref('product1'))
assert total_qty == 0, "Total quantity in stock should be 0 as the backorder took everything out of stock"
assert product.qty_available == 0, "Quantity available should be 0 too"