Skip to Content
Menu
This question has been flagged
1 Reply
2606 Views

Hi! I've created a button on the header of an MO to auto-validate the picking items and attached a server action to it but the server action doesn't seem to work. Help?

pickings = env['stock.picking'].search(['&',('origin','=',record.name),('picking_type_id','=',21)])

for picking in pickings:
picking.action_confirm()
picking.action_assign()

# process and validate the material picking transaction
move_items = env['stock.move'].search([('picking_id','=',picking.id)])

for move in move_items:
move\.move_line_ids\.write\(\{'qty_done':\ move\.product_uom_qty\}\)
\ \ \ \ move\['is_done'\]\ =\ True
\ \ \ \ move\['state'\]\ =\ 'done'

\ \ \#\ process\ the\ material\ pickings\ for\ material\ consumption\ of\ the\ production\ order
\ \ record\.action_assign\(\)
\ \ \#\ process\ and\ create\ move\ line\ for\ the\ production\ material\ requirements
\ \ move_items\ =\ env\['stock\.move'\]\.search\(\['\&',\('picking_type_id','=',23\),\('raw_material_production_id','=',record\.id\)\]\)
\ \
\ \ for\ move\ in\ move_items:
\ \ \ \ move\.move_line_ids\.write\(\{'qty_done':\ move\.product_uom_qty\}\)
\ \ \ \ move\['state'\]\ =\ 'assigned'
\ \ \ \
\ \ date_done\ =\ datetime\.datetime\.today\(\)
\ \ picking\['date_done'\]\ =\ datetime.datetime.strftime(date_done, '%Y-%m-%d %H:%M:%S')
picking['state'] = 'done'
picking.button_validate()
Avatar
Discard
Best Answer

Sometimes the picking raise warning during validation action. you have bypass these warning. i.e. 

pickings_to_validate = pickings.filtered(lambda picking:picking.state in ['assigned'])
pickings_to_validate.with_context(skip_backorder=True,skip_immediate=True).button_validate()
Avatar
Discard
Author

Can you guide me how to force the stock move even if the item lacks the required quantity?

Also, how do I process the production raw material stock moves after auto-validating the picking so that it shows that the materials had been reserved?

follow the same procedure for every picking in the production

Related Posts Replies Views Activity
2
Sep 23
5607
1
Apr 24
1474
1
Dec 23
2746
1
Apr 23
1749
2
Nov 22
2427