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

Hello 

 I need to restrict removing attachment from purchase order page in the state (purchase)

thank you in advance


アバター
破棄

See how to override unlink method: https://goo.gl/4BkizH

最善の回答

You need to inherit the ir.attachment object and override the unlink method. Now, in this method, check the res model and res_id. If it is of purchase order, then just browse it and check the state of the purchase and raise exception based on your need.

アバター
破棄
著作者

Thanks Sudhir

I tried same method,and also override the create method for restrict adding attachment is done state.it will works fine in local server.but i push in my production it will cause error when printing any pdf reports.
my code is like below,

class IrAttachment(models.Model):
# _inherit = 'ir.attachment'
#
# @api.model
# def create(self, vals):
# if vals.get('res_model') == 'purchase.order':
# po = self.env['purchase.order'].browse(vals.get('res_id'))
# if po.state == 'done':
# raise UserError('Can not add Attachments in Locked State')
# else:
# return super(IrAttachment, self).create(vals)
#
# @api.multi
# def unlink(self):
# if self.res_model == 'purchase.order':
# po = self.env['purchase.order'].browse(self.res_id)
# if po.state == 'done':
# raise UserError('Can not Delete Attachments in Locked State')
# else:
# return super(IrAttachment, self).unlink()

最善の回答

You inherit class IrAttachment and create custom unlink() method 

アバター
破棄
関連投稿 返信 ビュー 活動
2
11月 21
7697
4
12月 22
4588
0
10月 21
2601
4
3月 21
10918
2
11月 17
6889