Skip to Content
Menu
This question has been flagged

Hello,


I have a problem with get id.

I create the TransientModel which open a new window with selected records and in this i have my email composer.

And when i select email template i have this method:

    @api.onchange('email_template_id')
    def _onchange_template_id(self):
        if self.email_template_id:
            print('self1', self)
            print('self2', self._origin)
            print('self3', self._origin.id)
            print('self4', self.id)
            print('currency_id', self.currency_id)
            values = self.env['mail.compose.message'].generate_email_for_composer(self.email_template_id.id, [self._origin.id])[self._origin.id]
            self.email_body = values['body']

and i wanna to use composer to create body from my template.
But with this NewId i can't use generate_email_for_composer.

Debug for my prints:

self1 purchase.order.groupmail.wizard(<NewId 0x7f905ff24e90>,)
self2 purchase.order.groupmail.wizard()
self3 False
self4 <NewId 0x7f905ff24e90>
currency_id res.currency(17,)

Avatar
Discard
Best Answer

Hi @LukaszK

Without a complete Transient model definition I see that you talk about selected records but you don't show us the code for those records. They are records in a Many2many field? or they are previously selected records that you could get from self.env.context.get('active_ids') ??

Those records from the same model as the template are the ones that you need to use in the method call generate_email_for_composer

The debugs that you showed were related to a transient model that it will not exists until you save it and that's why you are getting a NewId values.

Also if the selected records are in a field or in the context you would need to check for values before calling generate_email_for_composer and pass it as a list of Integers

Avatar
Discard
Related Posts Replies Views Activity
2
Oct 19
5865
1
Dec 24
1491
2
Jan 24
1953
2
Jan 24
8215
1
Feb 23
1105