113 lines
5.8 KiB
YAML
113 lines
5.8 KiB
YAML
-
|
|
Create a new "negative" stockable product
|
|
-
|
|
!record {model: product.product, id: product_neg}:
|
|
name: Negative 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
|
|
qty: 5.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: pick_neg}:
|
|
name: Incoming picking
|
|
partner_id: base.res_partner_2
|
|
picking_type_id: picking_type_in
|
|
move_lines:
|
|
- product_id: product_neg
|
|
product_uom_qty: 300.00
|
|
location_id: stock_location_suppliers
|
|
location_dest_id: stock_location_stock
|
|
-
|
|
Confirm and assign picking and prepare partial
|
|
-
|
|
!python {model: stock.picking}: |
|
|
self.action_confirm(cr, uid, [ref('pick_neg')], context=context)
|
|
self.do_prepare_partial(cr, uid, [ref('pick_neg')], context=context)
|
|
-
|
|
Put 120 pieces on Palneg 1 (package), 120 pieces on Palneg 2 with lot A and 60 pieces on Palneg 3
|
|
-
|
|
!python {model: stock.picking}: |
|
|
#Change quantity of first to 120 and create 2 others quant operations
|
|
record = self.browse(cr, uid, ref('pick_neg'), context=context)
|
|
stock_pack = self.pool.get('stock.pack.operation')
|
|
stock_quant_pack = self.pool.get('stock.quant.package')
|
|
#create lot A
|
|
lot_a = self.pool.get('stock.production.lot').create(cr, uid, {'name': 'Lot neg', 'product_id': ref('product_neg')}, context=context)
|
|
#create package
|
|
package1 = stock_quant_pack.create(cr, uid, {'name': 'Palneg 1'}, context=context)
|
|
package2 = stock_quant_pack.create(cr, uid, {'name': 'Palneg 2'}, context=context)
|
|
package3 = stock_quant_pack.create(cr, uid, {'name': 'Palneg 3'}, context=context)
|
|
#Create package for each line and assign it as result_package_id
|
|
#create pack operation
|
|
stock_pack.write(cr, uid, record.pack_operation_ids[0].id, {'result_package_id': package1, 'product_qty': 120})
|
|
new_pack1 = stock_pack.create(cr, uid, {'product_id': ref('product_neg'), 'product_uom_id': ref('product.product_uom_unit'), 'picking_id': ref('pick_neg'), 'lot_id': lot_a, 'result_package_id': package2, 'product_qty': 120}, context=context)
|
|
new_pack2 = stock_pack.create(cr, uid, {'product_id': ref('product_neg'), 'product_uom_id': ref('product.product_uom_unit'), 'picking_id': ref('pick_neg'), 'result_package_id': package3, 'product_qty': 60}, context=context)
|
|
-
|
|
Transfer the reception
|
|
-
|
|
!python {model: stock.picking}: |
|
|
self.do_partial(cr, uid, [ref('pick_neg')], context=context)
|
|
-
|
|
Make a delivery order of 300 pieces to the customer
|
|
-
|
|
!record {model: stock.picking, id: delivery_order_neg}:
|
|
name: outgoing picking
|
|
partner_id: base.res_partner_4
|
|
picking_type_id: stock.picking_type_out
|
|
move_lines:
|
|
- product_id: product_neg
|
|
product_uom_qty: 300.00
|
|
location_id: stock_location_stock
|
|
location_dest_id: stock_location_customers
|
|
-
|
|
Assign and confirm
|
|
-
|
|
!python {model: stock.picking}: |
|
|
self.action_confirm(cr, uid, [ref('delivery_order_neg')], context=context)
|
|
self.action_assign(cr, uid, [ref('delivery_order_neg')])
|
|
-
|
|
Instead of doing the 300 pieces, you decide to take pallet 1 (do not mention product in operation here) and 140 pieces from lot A/pallet 2 and 10 pieces from pallet 3
|
|
-
|
|
!python {model: stock.picking}: |
|
|
stock_pack = self.pool.get('stock.pack.operation')
|
|
self.do_prepare_partial(cr, uid, [ref('delivery_order_neg')], context=context)
|
|
delivery_id = self.browse(cr, uid, ref('delivery_order_neg'), context=context)
|
|
for rec in delivery_id.pack_operation_ids:
|
|
if rec.package_id.name == 'Palneg 2':
|
|
lot_ids = self.pool.get("stock.production.lot").search(cr, uid, [('product_id', '=', ref('product_neg')), ('name','=','Lot neg')])
|
|
stock_pack.write(cr, uid, [rec.id], {'product_id': ref('product_neg'), 'product_qty': 140, 'lot_id': lot_ids[0]}, context=context)
|
|
if rec.package_id.name == 'Palneg 3':
|
|
stock_pack.write(cr, uid, [rec.id], {'product_id': ref('product_neg'),'product_qty': 10}, context=context)
|
|
-
|
|
Process this picking
|
|
-
|
|
!python {model: stock.picking}: |
|
|
self.do_partial(cr, uid, [ref('delivery_order_neg')], context=context)
|
|
-
|
|
Check the quants that you have 120 pieces pallet 1 in customers, 100 pieces pallet 2 in stock and 20 with customers and 50 in stock, 10 in customers from pallet 3
|
|
-
|
|
!python {model: stock.quant}: |
|
|
reco_id = self.search(cr ,uid , [('product_id','=',ref('product_neg'))], context=context)
|
|
for rec in self.browse(cr, uid, reco_id, context=context):
|
|
if rec.package_id.name == 'Palneg 1' and rec.location_id.id == ref('stock_location_customers'):
|
|
assert rec.qty == 120, "Should have 120 pieces on pallet 1"
|
|
elif rec.package_id.name == 'Palneg 2' and rec.location_id.id == ref('stock_location_stock'):
|
|
assert rec.qty == -20, "Should have -20 pieces in stock on pallet 2"
|
|
assert rec.lot_id.name == 'Lot neg', "It should have kept its Lot"
|
|
elif rec.lot_id.name == 'Lot neg' and rec.location_id.id == ref('stock_location_customers'):
|
|
assert ((rec.qty == 20 or rec.qty == 120) and not rec.package_id), "Should have 140 pieces (120+20) in customer location from pallet 2 and lot A"
|
|
elif rec.package_id.name == 'Palneg 3' and rec.location_id.id == ref('stock_location_stock'):
|
|
assert rec.qty == 30 or rec.qty == 20, "Should have 30 and 20 pieces in stock on pallet 3"
|
|
elif not rec.package_id and not rec.lot_id and rec.location_id.id == ref('stock_location_customers'):
|
|
assert rec.qty == 10, "Should have 10 pieces in customer location from pallet 3"
|
|
else:
|
|
assert False, "Unrecognized quant" |