Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
4164 Lượt xem

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()
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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()
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 9 23
6929
2
thg 1 25
6754
computed fields Đã xử lý
1
thg 4 24
2720
1
thg 12 23
4914
1
thg 4 23
4035