跳至内容
菜单
此问题已终结
2 回复
61221 查看

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?

形象
丢弃
最佳答案

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, 


形象
丢弃
编写者

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

最佳答案

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 ;)

形象
丢弃
相关帖文 回复 查看 活动
1
7月 20
4901
0
8月 19
2577
4
7月 24
10625
1
2月 23
1792
2
2月 23
2608