I want to modify CRM module in Odoo, so that customer can manage
multiple lead in single form. For that I created a parent, child
relationship. Both are in the same model crm.model.
#Parent save id of child.
parent_id = fields.Many2one('crm.lead', string="Parent Lead", ondelete="cascade")
# Child save id of parent.
child_ids = fields.One2many('crm.lead', 'parent_id', string="Child Lead", ondelete="cascade" )
Now, I want to write code such that, whenever user enter data into the parent lead it will auto fill into the child lead.
So far, I have tried following:
1. Add onchange function, but is executing but doesn't updating the fields i child.
@api.onchange('child_ids','net_net_all')
def _update_values(self):
detail = []
if not self.parent_id:
partner_probability = self.probability
self.balance = self.net_net_all
for record in self.child_ids:
self.balance -= record.net_net_child_all
detail.append((0,0,{
'reference': self.reference,
'partner_id': self.partner_id,
'agency': self.agency,
'partner_contact': self.partner_contact,
'agency_contact': self.agency_contact,
'agent_commission': self.agent_commission,
'email_from': self.email_from,
'phone': self.phone,
'user_id': self.user_id,
'team_id': self.team_id,
'region': self.region,
'segement': self.segement,
'type_of_advertisement': self.type_of_advertisement,
'planned_revenue_all': record.net_net_child_all * partner_probability,
'planned_revenue': record.net_net_child * partner_probability,
}))
return {'value' : {'child_ids' : detail}}
2.
Modifying **create** function but only effecting when the lead is
created and not when the lead is modifying. Also, taking much time to
execute properly.
if len(vals) == 1 and 'message_follower_ids' in vals.keys():
for record in self.child_ids:
record.reference = self.reference
record.partner_id = self.partner_id
record.agency = self.agency
record.partner_contact = self.partner_contact
record.agency_contact = self.agency_contact
record.agent_commission = self.agent_commission
record.email_from = self.email_from
record.phone = self.phone
record.user_id = self.user_id
record.team_id = self.team_id
record.region = self.region
record.segement = self.segement
record.type_of_advertisement = self.type_of_advertisement
Please suggest a work around.