ATTACHMENTS

Attachments are stored on the model `*ir.attachment* <http://hg.tryton.org/trytond/file/3.2/trytond/ir/attachment.py#l26>`_.

Attachments are linked to other models by the field `*resource* <http://hg.tryton.org/trytond/file/3.2/trytond/ir/attachment.py#l39>`

GET THE ATTACHMENTS

To get all attachments for that are linked for example to a specific product use this request::

{

"id": 1,
"method":"model.ir.attachment.search_read",
"params":[

userid,
sessionid,
[('resource', '=', 'product.template,4')],
0,
None,
[('name', 'ASC')],
['id', 'name', 'type', 'data', 'description', 'summary', 'link'],
context # Replace this with a full context

]

}

Most important is the part of the search domain: ('resource', '=', 'product.template,4').
This search domain means: Give me all attachments where the resource field has the value: 'product.template,4'.
The first part of the value describes the model of the resource ('product.template' in this example).
The second part of the value is the id of the specific record of the model (in this example: 4).
These two values are always separated by a comma.

To identify if a record does have attachments you can make a request like this::

{

"id": 1,
"method":"model.ir.attachment.search_count",
"params":[

userid,
sessionid,
[('resource', '=', 'product.template,4')],
context # Replace this with a full context

]

}

This will return the number of attachments for the specific record.