Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

problem changing values (NameError: global name 'diary_wage' is not defined)

By
Giovanny Vizcaya
on 2/11/15, 2:50 PM 999 views

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.

2

Vasanth

--Vasanth--
3458
| 5 3 8
Pondicherry, India
--Vasanth--
Vasanth
On 2/12/15, 12:42 AM

 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}

 

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 2/11/15, 3:17 PM

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"),

 

0
Giovanny Vizcaya
On 2/11/15, 4:02 PM

what you mean with multi="_get_FOO"?

answer updated

zbik
on 2/11/15, 4:06 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/11/15, 2:50 PM
Seen: 999 times
Last updated: 3/16/15, 8:10 AM