Hello, I use Odoo14, I want to transform this:
if order.state not in ('draft', 'cancel'):
raise UserError(_('You can not delete a sent quotation or a confirmed sales order. You must first cancel it.'))
and add 'custom_state' to the 'not in' condition.
I still want to call the super() so I will not loose chance of third party modules extension for sale order unlink method.
I tried to monkey patch by doing the following, which cause Python maximum recursion error when condition is verified.
import odoo
from odoo import models, fields, api, _
class SaleOrder(models.Model):
_inherit = 'sale.order'
def unlink_patched(self):
for order in self:
if order.state not in ('draft', 'cancel', 'custom_state'):
raise UserError(_('You can not delete a sent quotation or a confirmed sales order. You must first cancel it.'))
return super(SaleOrder, self).unlink()
odoo.addons.sale.models.sale.SaleOrder.unlink = SaleOrder.unlink_patched
For now I solved on xml side, by showing 'cancel' button on 'custom_state' so I can put state on 'cancel' then unlink record manually, but I'd like to be able to unlink without put the order in cancel state. Possible somehow ?
@Mehjabin Farsana This is litterally the solution to my situation, thank you very much, it works! :) I needed to specify explicitly the native SaleOrder class in super() instead of my class.
Thank you very much and thanks Odoo Mates, this guy is always helping. Too bad I can't upvote answer for lack of karma