Pawan Kumar Sharma
Pawan Kumar Sharma

Reputation: 1168

How to override unlink method for sale order in odoo10

Hello all i try to override unlink method of sale order line. Function called but raise UserError validation not removed.

Odoo default function:

@api.multi
def unlink(self):
    if self.filtered(lambda x: x.state in ('sale', 'done')):
        raise UserError(_('You can not remove a sale order line.\nDiscard changes and try setting the quantity to 0.'))
    return super(SaleOrderLine, self).unlink()

Custom Override function:

@api.multi
def unlink(self):
    if self.filtered(lambda x: x.state in ('sale', 'done')):
        pass
    return super(test, self).unlink()

Thanks in advance.

Upvotes: 1

Views: 1276

Answers (2)

dbrus
dbrus

Reputation: 79

As Cherif suggested, you can by pass any of the step in the super inheritance workflow.
In your case, if you want to call straightly the models.Model unlink method, try this way:

@api.multi
def unlink(self):
    if self.filtered(lambda x: x.state in ('sale', 'done')):
        pass
    return super(models.Model, self).unlink()

Something similar has been discussed in How can override write method without executing the super write?

Hoping that's answered your question

Upvotes: 1

Charif DZ
Charif DZ

Reputation: 14741

When you inherit a model and override a method. And you call super odoo keep the chaning.

Means in your case odoo calls your method --> sale.order method --> models.Model method

From what i understand you want to pass the validation means you don't want odoo to call unlink your unlink method ---> models.Model unlink

Don't use super try this i think it should work if not i will show an other solution

    return models.Model.unlink(self)

Upvotes: 1

Related Questions