コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
61184 ビュー

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
4885
0
8月 19
2561
4
7月 24
10612
1
2月 23
1764
2
2月 23
2584