Skip to Content
Menu
This question has been flagged
1 Reply
3786 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
Related Posts Replies Views Activity
4
Apr 24
170719
0
Dec 23
602
5
Nov 24
217114
1
Dec 22
1692
2
Nov 22
1678