Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1885 Vistas

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
Descartar
Autor

@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

Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
jun 23
2158
1
ene 22
3727
1
jun 20
4863
1
jun 20
35189
1
ene 20
2982