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

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 ?

Avatar
Discard
Author

@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

Best Answer

Hi,

The same case is explained in this video with solution: https://www.youtube.com/watch?v=luOmewgzXdQ

Can you check and see if it helps.

Thanks

Avatar
Discard
Related Posts Replies Views Activity
2
Jun 23
970
1
Jan 22
2347
1
Jun 20
3740
1
Jun 20
33174
1
Jan 20
2044