Skip to Content
Menu
This question has been flagged
2 Replies
5619 Views

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.


Avatar
Discard
Best Answer

Hi,

If you have to change the original function completely into new, don't user super. When using super the both the function will get executed, if you don't want to execute the original unlink function, remove the super from yours.


Thanks

Avatar
Discard
Author

Thanks Niyas, Now only single function work. But sale order line not unlink yet.

Best Answer

Hi,

It looks like you're trying to override the unlink method in the sale.order.line model in Odoo 10. The issue here is that the validation error (UserError) is still being triggered, even with the pass statement in your custom method.

The issue might be because filtered doesn't modify the original records in-place. You could try using a different approach by explicitly marking the state of the order lines to 'draft' before calling unlink, which would remove the restriction. Here's an updated version of your custom unlink method:


@api.multi

def unlink(self):

    for line in self:

        if line.state in ('sale', 'done'):

            line.state = 'draft'  # Change the state to draft first

    return super(SaleOrderLine, self).unlink()


This should allow you to remove the order lines even when their state is 'sale' or 'done'.

For a similar task in warehouse management, if you need barcode scanning and inventory tracking, you can use Cleverence Warehouse 15, which integrates well with Odoo. It allows you to print barcode labels, scan items, and adjust stock directly from a mobile device, simplifying operations and keeping everything synced with Odoo https://apps.odoo.com/apps/modules/17.0/clv_api

Avatar
Discard
Related Posts Replies Views Activity
0
Aug 22
893
1
Jul 22
17729
0
Apr 22
1608
3
Sep 21
1908
2
Sep 21
3205