Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
61124 Vizualizări

i have:

class CalendarEvent(models.Model):
_name = 'calendar.event'

and

class Lead(models.Model):
_name = 'crm.lead'
meeting_ids = fields.Many2many('calendar.event')


and i need to override the create method on calendar.event so that when a new envent is created, is automaticlly insrted into meeting_ids
i've tried with:
​leads = self.env['crm.lead']
for lead in leads:
    lead.meeting_ids = [(0, 0, {'name': self.name,
'start': self.start,
'stop': self.stop})
 or with
lead.meeting_ids = [(4, self.id)] ​  ​

butnothing works, can anyone help me?

Imagine profil
Abandonează
Cel mai bun răspuns

Hello,

Please try this for Many2many records,y ou need to use super call of create method for CalendarEvent model, and insert it in your leads. 

event_id = super(CalendarEvent, self). create(vals)

​leads = self.env['crm.lead']. search(your domain)
for lead in leads:
    lead.meeting_ids = [(4, [event_id.id])]     

Or

    lead.write({'meeting_ids': [(4, [event_id.id])] })                                                                                                                                   


Hope it will work for you, 

Thanks, 


Imagine profil
Abandonează
Autor

I've tried like that but it didn't do anything...

I did it like this:

leads = self.env['crm.lead'].search([('partner_id', '=', self.opportunity_id_partner_id.id)])

for lead in leads:

lead.related_events = [(4, self.id)]

only in the write() method and it works!

But thanks

@Rick: verified answer, even it's still working for Odoo 16

Cel mai bun răspuns

For me in Odoo v13 works this way:

template = self.sale_order_template_id_selector.with_context(lang=self.partner_id.lang)

if template:
    self.sale_order_template_ids = [(4, template.id)]

Happy hunting ;)

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
iul. 20
4866
0
aug. 19
2551
4
iul. 24
10590
1
feb. 23
1739
2
feb. 23
2570