Hi masters.
I have a pdf in a many2many field relate to ir.attachment.
But when a common user try to acces the module, the error appears.
How can I avoid this without adding the user to the admin group?
Thanks in advance!
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hi masters.
I have a pdf in a many2many field relate to ir.attachment.
But when a common user try to acces the module, the error appears.
How can I avoid this without adding the user to the admin group?
Thanks in advance!
Theres an issue about this:
https://github.com/odoo/odoo/pull/82111
This is the cause:
"Attachments that are uploaded on a record that isn't saved yet are
created with res_id set to 0. In the case of attachments linked through
a m2m rather than the usual (res_model, res_id), it means they may not
be readable afer the creation of the record, except by their creator.
Re-attaching them to the mailing / template at the end of the create()
call fixes the ownership."
I solved adding this in my custom module:
" @api.model
def create(self, vals):
templates = super(RoomsReservation,self).create(vals)
# fix attachment ownership
for template in templates:
if template.attachment_ids:
template.attachment_ids.write({'res_model': self._name, 'res_id': template.id})
return templates"
I have same issue. I had extend model ir.attachment. And i have an issue, when i try to enter in model which connected many2many to new attachment model. I check solution above, and it works for new records, but it doesn't when i updating records. Can you help me with this? I try to do same on write function of parent model, but it doesn't work either.
like this
`
def write(self, vals):
for record in self:
print(record.document_ids)
record.document_ids.write({'res_model': self._name, 'res_id': record.id})
return super(Project, self).write(vals)
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 | |
---|---|---|---|---|
|
1
thg 7 24
|
3921 | ||
|
1
thg 4 25
|
4523 | ||
|
0
thg 12 23
|
1033 | ||
|
1
thg 2 23
|
2256 | ||
|
0
thg 2 23
|
157 |
Theres an issue about this:
https://github.com/odoo/odoo/pull/82111
This is the cause:
"Attachments that are uploaded on a record that isn't saved yet are
created with res_id set to 0. In the case of attachments linked through
a m2m rather than the usual (res_model, res_id), it means they may not
be readable afer the creation of the record, except by their creator.
Re-attaching them to the mailing / template at the end of the create()
call fixes the ownership."
I solved adding this in my custom module:
" @api.model
def create(self, vals):
templates = super(RoomsReservation,self).create(vals)
# fix attachment ownership
for template in templates:
if template.attachment_ids:
template.attachment_ids.write({'res_model': self._name, 'res_id': template.id})
return templates"