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()