I would like to make it easy to add attachments to the res.partner
model in my views. As a result, I've figured out that I can extend the res.partner
model easily with a many2many field to ir.attachment
.
_columns = {
'attachments': fields.many2many('ir.attachment', string="Attachments")
}
Now when I add this field to my view I see the list of attachments, but I have 2 problems with this simple many2many widget.
- I need too many clicks to get a new file attached. First, it opens the many2many cross table where I could select already uploaded documents. Second, I can open the upload view. The intermediate screen is obviously not needed for me, as this view is used to create new partners, thus the already uploaded files will never be re-used.
- I would like the upload view to have its relational fields filled out. These fields are res_model=res.partner, res_id= and partner_id=.
I don't have any ideas on how to get rid of the first, intermediate view problem outlined below.
I've had an idea on how to solve the second problem, to pre-fill out the upload view's data. I wrote this in my view xml
<field name="attachments"
context="{'default_res_model': 'res.partner', 'default_res_id': active_id, 'default_partner_id': active_id}"/>
Unfortunately, this does not work, as active_id=0
, instead of it being active with the new resource id (this might not even exist?).
Do you have any idea on (1) how to get an immediate upload view and (2) how to get the new record's id into the upload view?