I'd like to delete all Sales Order/Quotations in Odoo 11.
For quotations, I was using the Odoo GUI to batch delete them. But for Sale Orders, I must firstly cancel them before deleting. This is time-consuming by the GUI way (because we cannot mass cancel Sale Orders).
So I think doing that programmatically would be better (in terms of time). However, the current code
orders = self.env['sale.order'].search([('external_id', '!=', '')])
for order in orders:
order.unlink()
raises an exception of
You can not delete a sent quotation or a sales order! Try to cancel it before.
How can I cancel order
before unlink()
ing them?