Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
2 Respostas
3496 Visualizações

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
Cancelar
Autor

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

Autor Melhor resposta

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
Cancelar
Publicações relacionadas Respostas Visualizações Atividade
0
out. 20
3731
5
out. 19
9506
0
out. 15
4744
4
ago. 15
4745
2
jul. 25
2740