Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
1940 Visualizzazioni

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
Abbandona
Autore

@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

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
giu 23
2226
1
gen 22
3806
1
giu 20
4990
1
giu 20
35271
1
gen 20
3068