@api.multi
def action_create_history(self):
for reg in self:
history_data = {}
history_data['corporate_id'] = reg.id
for staff in reg.member_ids :
history_data['name_id'] = staff.id
history_data['state_old'] = ''
history_data['state_new'] = 'valid'
history_data['old_date'] = ''
history_data['state'] = 'complete'
if reg.membership_period == '1' :
history_data['new_date'] = datetime.today() + timedelta(days=365)
print('=========== member_ids ==================', reg.member_ids)
print('=========== History DAta ==================', history_data)
reg.history_ids = [(0, 0 , history_data)]
print('=========== history_ids ==================', reg.history_ids)
Result :
=========== member_ids ================== res.partner(281, 280, 279)
=========== History DAta ================== {'corporate_id': 14, 'name_id': 279, 'state_old': '', 'state_new': 'valid', 'old_date': '', 'state': 'complete', 'new_date': datetime.datetime(2020, 6, 29, 10, 20, 55, 106029)}
=========== history_ids ================== membership.history(159, 160, 161, 162, 164, 165, 166, 171)
=========== member_ids ================== res.partner(281, 280, 279)
=========== History DAta ================== {'corporate_id': 14, 'name_id': 279, 'state_old': '', 'state_new': 'valid', 'old_date': '', 'state': 'complete', 'new_date': datetime.datetime(2020, 6, 29, 10, 20, 55, 442465)}
=========== history_ids ================== membership.history(159, 160, 161, 162, 164, 165, 166, 171, 172)
=========== member_ids ================== res.partner(281, 280, 279)
=========== History DAta ================== {'corporate_id': 14, 'name_id': 279, 'state_old': '', 'state_new': 'valid', 'old_date': '', 'state': 'complete', 'new_date': datetime.datetime(2020, 6, 29, 10, 20, 55, 833930)}
=========== history_ids ================== membership.history(159, 160, 161, 162, 164, 165, 166, 171, 172, 173)
please help me to solve this and explain why system always loop the same id even though there is 3 id on the list ?
From your post the indentation is not clear. please post as image for more clarity. form initial check only last member detail is updated in history_data.