コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
2010 ビュー

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 ?

アバター
破棄
著作者

@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

最善の回答

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

アバター
破棄
関連投稿 返信 ビュー 活動
2
6月 23
2326
1
1月 22
3868
1
6月 20
5085
1
6月 20
35368
1
1月 20
3122