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

TypeError: onchange_getage() takes at most 6 arguments (7 given)

By
Jothimani
on 3/29/14, 2:50 AM 2,868 views

Hi currently doing a project, which is used for employee registration. here is my code..

error in my project,

TypeError: onchange_getage() takes at most 6 arguments (7 given)

here is my code

in jebatraining_view.xml

<record id="view_employee_form" model="ir.ui.view">
    <field name="name">jebatraining.form_view</field>
    <field name="model">employee_data</field>
    <field name="type">form</field>
    <field name="arch" type="xml">
        <form string="Employee Details">
            <field name="ename" string="Employee Name"/>
            <field name="fname" string="Fathers Name"/>
            <field name="gender" string="Gender"/>
            <field name="dob" on_change = "onchange_getage(dob)" string="Date of Birth"/> 
            <field name="age" string="Age"/>
            <field name="mobile" string="Mobile"/>
            <field name="website" string="Website"/>            
            <field name="email" string="Email"/>
            <field name="address" string="Address"/>
            <field name="pincode" string="Pincode"/>
            <field name="doj" string="Date of Joining"/>
        </form>
    </field>
 </record>

in jebatraining.py

from datetime import date,datetime
from time import strptime
from dateutil import parser
from openerp.osv import osv, fields

class jebatraining(osv.osv):
    _name = "employee_data"
    _description = "Employee management"

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

        current_date=datetime.now()

        current_year=current_date.year

        birth_date=parser.parse(dob)

        current_age=current_year-birth_date.year

            return {'value':{'age': current_age}} 

    _columns = {
        'ename':fields.char('Employee Nmae', size=50, required=True),
        'fname':fields.char('Fathers Name', size=50, required=True),
        'gender':fields.selection((('male','Male'),('female','Female')),'Gender'),
        'dob':fields.date('Date of Birth', required=True),

        'mobile':fields.char('Mobile Number', size=10),
        'salary':fields.float('Salary'),        
        'email':fields.char('Email', size=30),
        'website':fields.char('Website', size=30),      
        'address':fields.text('Address'),
        'pincode':fields.integer('Pincode', size=6),
        'doj':fields.date('Date of joining'),
        }
jebatraining()

anyone let me to know this solution... Thanks......

2

Nehal

--Nehal--
2090
| 5 2 8
Ahmadabad, India
--Nehal--
Nehal
On 3/29/14, 2:59 AM

Hi,

'age':fields.function(onchange_getage, type='integer', method=True, string='Age'),

For function field, you will not get dob parameter. For that you need to browse record. As you are defining onchange in xml file for dob, you will get age by return following: return {'value':{'age': current_age}}

You don't need to define function in age field.

THanks dude,,, it works,,, but error when, i was create entry and viewing entry. TypeError: onchange_getage() takes at most 6 arguments (7 given)

Jothimani
on 3/29/14, 3:10 AM

You dont having onchange function, you having function field remove in xml onchange parameter then check it.

sridhar
on 3/29/14, 3:18 AM

Sridhar, i want age calculation when i select dob in form to edit, suddenly calculate age show age in form, thats yi using on_change event in xml,,,

Jothimani
on 3/29/14, 3:27 AM

You using as a functional field when you save it value come automatically, here no need onchange remove it and then check.

sridhar
on 3/29/14, 3:29 AM

Either remove onchange method or function field. If you want to show age while saving the record, make it as function field. Onchange will give you age on select of dob. it could be like: <field name="dob" on_change = "onchange_getage(dob)" string="Date of Birth"/> OR if you are using function field, you need to change the function like : onchange_getage(self, cr, uid, ids, field_name, arg, context=None):

Nehal
on 3/29/14, 3:37 AM

all dudes....!!! its working without errors.... thanks lot to all......

Jothimani
on 3/29/14, 3:38 AM
0

Med Said BARA

--Med Said BARA--
2664
| 5 5 7
Algeria
--Med Said BARA--
Med Said BARA
On 3/29/14, 5:28 AM

Hi;

Do you think that something like the following, can be used:

Extracted from

def _calculate_age(self, cr, uid, ids, field_name, arg, context=None):

    res = dict.fromkeys(ids, False)
    for ee in self.browse(cr, uid, ids, context=context):
        if ee.dob:
            dBday = datetime.strptime(ee.dob, OE_DFORMAT).date()
            dToday = datetime.now().date()
            res[ee.id] = (dToday - dBday).days / 365
    return res

 _columns = {
                           'age': fields.function(_calculate_age, type='integer', method=True, string='Age'),
}

Best regards.

0
sridhar
On 3/29/14, 3:24 AM

Change like this, _name is like employee.data, dont use employee_data, its make error. class jebatraining(osv.osv): _name = "employee.data" your code, and change xml

<record id="view_employee_form" model="ir.ui.view"> <field name="name">jebatraining.form_view</field> <field name="model">employee_data</field> <field name="type">form</field> <field name="arch" type="xml"> <form string="Employee Details"> <field name="ename" string="Employee Name"/> <field name="fname" string="Fathers Name"/> <field name="gender" string="Gender"/> <field name="dob" string="Date of Birth"/> <field name="age" string="Age"/> <field name="mobile" string="Mobile"/> <field name="website" string="Website"/>
<field name="email" string="Email"/> <field name="address" string="Address"/> <field name="pincode" string="Pincode"/> <field name="doj" string="Date of Joining"/> </form> </field> </record> Try now.

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

0 follower(s)

Stats

Asked: 3/29/14, 2:50 AM
Seen: 2868 times
Last updated: 3/16/15, 8:10 AM