ERP-Ukraine / odoo-rpc-dart

Odoo RPC Library for Dart
MIT License
43 stars 32 forks source link

Can you please guide how to post with attachment like picture? #13

Closed function2000 closed 2 years ago

function2000 commented 3 years ago

Can you please guide how to post with attachment like picture? For example call method "message_post" with attachment picture. A detail example is appreciated.

lem8r commented 3 years ago

Hi!

You can post message with attachment in two rpc calls.

Mail message model has a hint how multiple attachments are linked to document and message. See https://github.com/odoo/odoo/blob/084d06a5892ab2723d02dc29f0e62377c554efac/addons/mail/models/mail_message.py#L45-L50

For instance, if you need to post message on sales order and you already know sale order's id:

  1. Create attachment with following fields.
    {
     'name': 'attachment.jpg',
     'datas': base64Encode(attachmentData),
     'type': 'binary',
     'description': 'attachment.jpg',
     'res_model': 'sale.order',
     'res_id': saleOrderId
    }
  2. After you got attachment id you can pass it to message_post as attachment_ids param wrapped in a list.
function2000 commented 3 years ago

Hi!

You can post message with attachment in two rpc calls.

Mail message model has a hint how multiple attachments are linked to document and message. See https://github.com/odoo/odoo/blob/084d06a5892ab2723d02dc29f0e62377c554efac/addons/mail/models/mail_message.py#L45-L50

For instance, if you need to post message on sales order and you already know sale order's id:

  1. Create attachment with following fields.
{
     'name': 'attachment.jpg',
     'datas': base64Encode(attachmentData),
     'type': 'binary',
     'description': 'attachment.jpg',
     'res_model': 'sale.order',
     'res_id': saleOrderId
}
  1. After you got attachment id you can pass it to message_post as attachment_ids param wrapped in a list.

Thank you very much! I will check then.