This question has been flagged
4 Replies
2818 Views

@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 ?

Avatar
Discard

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.

Best Answer

Hi Chaanto,

I think you would like to loop through reg.member_ids ('res.partner') instead of looping through self.

@api.multi
def action_create_history(self):
    self.ensure_one()
    for member in self.member_ids:
        do_something​​
Avatar
Discard
Author

Hey, thanks for try fix my problem. i fix it already, the problem is about my hierarchy of my code.

Best regards,

Chaanto

Best Answer

Hello
There is issue of indentation of your code, if possible can you please show us your code lines (Screenshot).
So community can help you.

Avatar
Discard
Author

Hey Dude, thanks for your attention. i already fix the problem.

Best Regards,

Chaanto