Skip to Content
Menú
This question has been flagged

In Odoo 16, I need to validate certain stock.picking transfers programatically using a cron when they do not have the status 'canceled'.

However, if I use the actions also used in the database, the status is still on 'ready', the amount to process is all still in 'reserved' and no items are set to 'done'.

Does anyone know what I'm doing wrong? My code is the following:

	​order_id = existing_order.id
lines_to_ship = self.env['stock.picking'].search([('sale_id', '=', order_id), ('state', '!=', 'done'),
('state', '!=', 'canceled')])

if not lines_to_ship or len(lines_to_ship) < 1:
return

for
line_to_ship in lines_to_ship:
try:
success = line_to_ship.sudo().action_assign()
if not success:
continue
​ validated = line_to_ship.sudo().with_context({'skip_sanity_check': True, 'skip_immediate': True,
​ 'skip_backorder': True}).button_validate()

done = line_to_ship.sudo().with_context({'cancel_backorder': False})._action_done()
except Exception as e:
_logger.info(str(e))
continue
Avatar
Descartar
Related Posts Respostes Vistes Activitat
1
d’ag. 21
4033
1
de juny 21
4678
1
de maig 25
2386
1
d’abr. 25
3420
1
d’abr. 25
4225