콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
61484 화면

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
5018
0
8월 19
2717
4
7월 24
10818
1
2월 23
1947
2
2월 23
2751