コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
12210 ビュー

@api.multi
def action_undo_history(self):
    history_obj = self.env['membership.history']

    for reg in self:
        history_ids = history_obj.search([('name_id', '=', reg.name_id.id)], history_ids[0].date)
        history_ids = self.env['membership.history'].search([('name_id', '=', reg.name_id.id)], order='date desc')

        current_state = reg.name_id.state
        history_state = reg.state_new

        if history_ids[0] == reg and current_state == history_state:
            reg.name_id.state == reg.state_old

        else :
            message = _("Only the latest history can be cancelled !")
            mess= {
            'title': _('Error : Cancelling State'),
            'message' : message
            }
return {'warning': mess}

アバター
破棄
最善の回答

Hi,

You are getting this error because you are accessing the value from the field named history_ids in this line of the code before defining the field.

history_ids = history_obj.search([('name_id', '=', reg.name_id.id)], history_ids[0].date)


but, you haven't assigned what value should that variable hold. You should update your code such a way that you have to define the variable before using it.


for reg in self:
   history_ids = ?
 history_ids = history_obj.search([('name_id', '=', reg.name_id.id)], history_ids[0].date)
 history_ids = self.env['membership.history'].search([('name_id', '=', reg.name_id.id)], order='date desc')


Thanks

アバター
破棄
関連投稿 返信 ビュー 活動
1
7月 23
3006
2
7月 22
9156
1
5月 22
3122
1
6月 21
2449
2
2月 21
299