This question has been flagged
2 Replies
5475 Views

Hello,i'll describe problem in the detail.The main problem is that i can't save 'res_model' field in 'ir.attachment' table. I use odoo v12.0.


Budget model​

```

class AccountBudget(models.Model):
_name = "account.budget"

attachment_ids = fields.One2many('ir.attachment', 'id', string='Attachments')
```

Budget view

```

<field name="attachment_ids" context="{'default_res_model': 'account.budget',
'default_file_type': 'document'}">

</field>

```

As you can see, i set context wit default res_model. But when i click save button it doesn't save res_model.
File type work greatly.

This behavior only with One2Many relation. If i set 'attachment_ids' Many2Many all works fine.
But with Many2Many field i have one layer, that displayed all files, i don't need that.

How can i save attachment for certain res_model?

Avatar
Discard
Best Answer

Have you fixed the issue ? 

Avatar
Discard
Best Answer

Read the documentation on how to define the One2man relational field.
https://www.odoo.com/documentation/12.0/reference/orm.html#relational-fields
See definition inverse name:
inverse_name – name of the inverse Many2one field in comodel_name
Your inverse_name = id is not good.

Example:
invoice_line_ids = fields.One2many('account.invoice.line', 'invoice_id', string='Invoice Lines')

Avatar
Discard