跳至內容
選單
此問題已被標幟
3 回覆
5645 瀏覽次數

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
6817
4
12月 19
7385
1
2月 16
6524
1
12月 15
9426
0
8月 15
3490