Skip to Content
Menu
This question has been flagged
1 Reply
1274 Views

I am trying to overwrite the unlink method of the sale.order model.


class SaleOrderExtension(models.Model):

    _inherit = "sale.order"

    # ...

    def unlink(self):

        # ...

        return super(SaleOrderExtension, self).unlink()


It seems to work, but the check:

    if order.state not in ('draft', 'cancel'):

in the original sales model is still executed!

https://github.com/odoo/odoo/blob/14.0/addons/sale/models/sale.py#LC362


How can I remove this check?

Thank you!


Avatar
Discard
Best Answer

In last line, you are calling super() so  super() calls the method from sale.order, So don't need to call super()  but that will skip all unlink() overridden for sale.order by other modules. You can do that as below:


class SaleOrderExtension(models.Model):
_inherit = "sale.order"

def unlink(self):
# you custom code if any
return models.Model.unlink(self)

Avatar
Discard
Author

thank you

Related Posts Replies Views Activity
2
Jan 25
1890
1
Dec 24
5593
1
Nov 24
1937
1
Nov 24
1459
2
Sep 24
1331