Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
3503 Prikazi

I'm doing a large import of partners through the API (because the data is too complex to use CSV).

I would like to set the create_date and insert the messages into mail_message myself, so I can use the correct users, dates, etc.

My questions:

  • Can you manually create entries (ideally through the API)  into mail_message table (mail.message model) with custom date and creator?

  • Can you prevent the "Contact Created" and "Added to Company" messages from being created somehow?

  • And, optionally, is there a way to set the create_date / update_date for an import?

Avatar
Opusti
Avtor

This is for Odoo 11 - I've tried to edit the original post, but it didn't let me.

Avtor Best Answer

There is no way to do this without overriding a method on partner level.

My current solution:

During import, search model: mail.message for:

[
    ('model', '=', 'res.partner'),
    ('res_id', '=', partner_id),
    ('body', '=', '<p>Contact created</p>')
]

Then update the following fields:

        message_contents = {
            'date': new_date,
            'author_id': new_partner_id,
            'email_from': "Name <email@server.com>",
        }


-----------

Alternate solution:

Overriding the message_post method to prevent the message from being posted:

    @api.multi
    @api.returns('self', lambda value: value.id)
    def message_post(self, body='', subject=None, message_type='notification',
                     subtype=None, parent_id=False, attachments=None,
                     content_subtype='html', **kwargs):
        """ This whole method, and the property of skip_messages can be removed after import is finalized. """
        for partner in self:
            if partner.skip_messages:
                return None
        return super(ResPartner, self).message_post(
                body=body, subject=subject, message_type=message_type, subtype=subtype,
                parent_id=parent_id, attachments=attachments, content_subtype=content_subtype,
                **kwargs)

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
0
okt. 20
3742
5
okt. 19
9514
0
okt. 15
4745
4
avg. 15
4747
1
avg. 25
320