This question has been flagged
1 Reply
3427 Views

I want to clean up my sales.orders regualary (e-Commerce in odoo 11). 

So I wrote a script, which should delete 200 rows per execution:

dateTime = datetime.datetime.now() - datetime.timedelta(hours = 96)
emptyOffers = env['sale.order'].search(
[
('create_date', '<', dateTime.strftime('%Y-%m-%d %H:%M:%S')),
('amount_total', '=', '0')
]
)

i = 0;

for emptyOffer in emptyOffers:
emptyOffer.unlink()
raise Warning('unlink one') # <= Debug code
i = i + 1;

if i > 200:
break;

Everything works fine until "...unlink()". Then the script just runs into timeout => No message, No Exception, Not a single row was deleted

Does anyone know, what i missed?

Avatar
Discard
Best Answer

See this code in the sale.order model:

@api.multi
def unlink(self):
for order in self:
if order.state not in ('draft', 'cancel'):
raise UserError(_('You can not delete a sent quotation or a sales order! Try to cancel it before.'))
return super(SaleOrder, self).unlink()

Avatar
Discard