Hello
I need to restrict removing attachment from purchase order page in the state (purchase)
thank you in advance
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello
I need to restrict removing attachment from purchase order page in the state (purchase)
thank you in advance
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
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 11 21
|
7661 | ||
|
4
thg 12 22
|
4567 | ||
|
0
thg 10 21
|
2577 | ||
|
4
thg 3 21
|
10873 | ||
|
2
thg 11 17
|
6869 |
See how to override unlink method: https://goo.gl/4BkizH