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

Good day, i'm making a module that registers social benefits, this is my code:

    def _get_diary_wage(self, cr, uid, ids, field_name, arg, context= None):
        res = {}
        for rec in self.browse(cr,uid,ids,context):
            res[rec.id] = rec.month_wage / 30
        return res
    
    def _get_credit_utilities(self, cr, uid, ids, field_name, arg, context= None):
        res = {}
        for rec in self.browse(cr,uid,ids,context):
            res[rec.id] = (rec.diary_wage * rec.days_utils) / 360
        return res
    
    _columns = {
        'month_wage': fields.float('Month Wage', digits=(16,2)),
        'diary_wage': fields.function(_get_diary_wage, method=True, type='float', string='Diary Wage, store=True),
        'days_utils': fields.integer('Days of Utilities'),
        'credit_utilities': fields.function(_get_credit_utilities, method=True, type='float', string='Credits for Utilities', store=True),
    }
    
    def onchange_month_wage(self, cr, uid, ids, month_wage, context=None):
        vals = {}
        if month_wage > 0:
            vals['diary_wage'] = month_wage / 30
        return {'value': vals}
    
    def onchange_days_utils(self, cr, uid, ids, days_utils, context=None):
        vals = {}
            vals['credit_utilities'] = (diary_wage * days_utils) / 360
        return {'value': vals}

this code calculates the diary_wage perfectly, but when i'm going to calculate the credits_utilities writing the days_utils i get this error:

NameError: global name 'diary_wage' is not defined

Where i'm failing?

I'm working with version 7.

Thanks a lot in advance.

아바타
취소
베스트 답변

 You did not defined the value of "diary_wage" in the below onchange method:

def onchange_days_utils(self, cr, uid, ids, days_utils, context=None):
        vals = {}
         vals['credit_utilities'] = (diary_wage * days_utils) / 360
        return {'value': vals}

try this:

def onchange_days_utils(self, cr, uid, ids, days_utils, context=None):
        vals = {}

       diary_wages=1
        vals['credit_utilities'] = (diary_wage * days_utils) / 360
        return {'value': vals}

 

아바타
취소
베스트 답변

My suggestion, you try multi="_get_FOO" and the same _get_credit_and_wage  function for both fields.function. All fields with the same multi parameter will be calculated in a single function call.

UPDATE:

About Functional Fields - fields.function and about multi parameter read here

Example:

        'xxx' :  fields.function(_get_ABC,type='float',string='Total xxx', multi="FOO" ),
        'yyy' :  fields.function(_get_ABC,type='float',string='Total yyy', multi="FOO"),

 

아바타
취소
작성자 베스트 답변

what you mean with multi="_get_FOO"?

아바타
취소

answer updated

관련 게시물 답글 화면 활동
1
12월 15
6989
4
12월 19
7549
1
2월 16
6641
1
12월 15
9568
0
8월 15
3650