Hi,
In my custom module I have primary contact and its related complete details. The below mentioned code works fine when the primary contact remains same. But when the primary contact changes the complete details which is merged brings the previous contact's complete details along with daily activity note. Ideally the daily activity note should merge with new primary contact. But it's not happening. Can anyone look into it and help ?
Code for merging :
@api.model
def create(self, vals):
if vals.get('daily_activity_note'):
import datetime
now = datetime.datetime.now()
today = now.strftime("%Y-%m-%d %H:%M")
user = self.env.user.name
if self.compl_act:
vals['compl_act'] = str(today)+ ' - ' + str(user)+ ' - ' + str(vals.get('daily_activity_note')) +'\n'+str(self.compl_act)
else:
vals['compl_act'] = str(today)+ ' - ' + str(user)+ ' - ' + str(vals.get('daily_activity_note'))
vals['daily_activity_note'] = None
res = super(activity_one2, self).create(vals)
return res
@api.multi
def write(self, vals):
if vals.get('daily_activity_note'):
import datetime
now = datetime.datetime.now()
today = now.strftime("%Y-%m-%d %H:%M")
user = self.env.user.name
if self.compl_act:
vals['compl_act'] = str(today)+ ' - ' + str(user)+ ' - ' + str(vals.get('daily_activity_note')) +'\n'+str(self.compl_act)
else:
vals['compl_act'] = str(today)+ ' - ' + str(user)+ ' - ' + str(vals.get('daily_activity_note'))
vals['daily_activity_note'] = None
res = super(activity_one2, self).write(vals)
return res
Thanks and regards.
In create method why are you trying to access "self.compl_act" field? Your record is not yet created. Try it again after removing if condition in create method.
Hi Sudhir Arya,
Thanks for response.
The compl_act is related field of primary contact. So if such a contact is selected who has the details, it will have compl_act value and in that case (datetime + user + note + compl_act) should happen, else (datetime + user + note) should happen. That's why I have given self.compl_act in create method.
Moreover, I am not facing issue while creation of new record. Issue is only when primary contact changes in the existing record.
Suppose, There is prim_cont1 having compl_act1.
So if note is added, compl_act1 will be note+compl_act1
Now if the record is updated and now prim_cont2 having compl_act2 is selected.
So if note is added, compl_act2 should be note + compl_act2
But after saving it is becoming compl_act2 = note+compl_act1
and in this way the compl_act2 is lost.
Regards.