콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
12049 화면

I'm overriding the write() method in validation of odoo hr_attendance

My code is


def write(self, cr, uid, ids, context=None):

    for att in self.browse(cr, uid, ids, context=context):

        prev_att_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '<', att.name),

('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name DESC')

        next_add_ids = self.search(cr, uid, [('employee_id', '=', att.employee_id.id), ('name', '>', att.name),

('action', 'in', ('sign_in', 'sign_out'))], limit=1, order='name ASC')

        prev_atts = self.browse(cr, uid, prev_att_ids, context=context)

        next_atts = self.browse(cr, uid, next_add_ids, context=context)

            if prev_atts and prev_atts[0].action == att.action:

                return self.write(cr, uid, ids, {'state': True})

            if next_atts and next_atts[0].action == att.action: # next exists and is same action

                return self.write(cr, uid, ids, {'state': True})

            if (not prev_atts) and (not next_atts) and att.action != 'sign_in': # first attendance must be sign_in

                return self.write(cr, uid, ids, {'state': True})

            else:

                return self.write(cr, uid, ids, {'state': False})

return True

This is my code. While writing a record in attendance it should check the three "if condition" and want to change the value of the field "state" either "true or false" according to the "if conditions".


But the problem is, in attendance module I have created a record and when I press save it show this error


"

ValidateError

Error while validating constraint

write() got multiple values for keyword argument 'context'      "


How can I solve this issue? Help me


Thanks.


Regards,

Uppili Arivukkannu


아바타
취소
베스트 답변

Thanks for your reply Emipro Technologies


I have changed the code but it show this error


ValidateError

Error while validating constraint

maximum recursion depth exceeded


I have tried this code

import resource,sys
resource.setrlimit(resource.RLIMIT_STACK, (2**29,-1))
sys.setrecursionlimit(10**6)

But it automatically stops the odoo server

아바타
취소

Please do not call write() method from defination of the write() method. It is the cause infinite recursion. Please remove """ self.write(cr, uid, ids, {'state': True})""" from your code.

베스트 답변

Hello,

You have define wrong write method

def write(self, cr, uid, ids, context=None):

You have not write one argument "vals". So, vals are passed in context as well as default context is set. So, you got this error.

In that you have to pass following arguments thats it.

def write(self, cr, uid, ids, vals, context={})

It will resolve your issue.


아바타
취소
관련 게시물 답글 화면 활동
0
5월 16
9364
0
11월 15
6339
2
8월 25
1650
3
7월 25
2433
1
7월 25
2031