Swan White
Swan White

Reputation: 211

Openerp- How to call custom function inside the "create" function?

Please help me to solve this problem, I have a function which used to check validation terms of the input and I wants to call it inside the "create"function as a nested function. Once I call it in normal way it keeps giving me parameter mismatching error. Please help me. Inside the create function I call it like this

def create(self, cr, uid, values, context=None):

#There are 219 lines in side the create function but I just showing you the invoke for this particular fucntion.

   date_from = values['date_from']
   date_to=values['date_to']
   sub_nominee= values['sub_nominee']

   self.onchange_sub_nominee(self, cr, uid, date_to, date_from,sub_nominee)

  return super(hr_holidays, self).create(cr, uid, values, context=context)

Function is like this,

def onchange_sub_nominee(self, cr, uid,ids, date_to, date_from,sub_nominee):
    #Employees data
    DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
    from_dt = datetime.datetime.strptime(date_from, DATETIME_FORMAT).date()
    to_dt=datetime.datetime.strptime(date_to, DATETIME_FORMAT).date()

    sub_name=self.pool.get('hr.employee').browse(cr, uid, sub_nominee).name

    hol_obj=self.pool.get('hr.holidays')

    #if date_from==date_to:
    hol_objs=hol_obj.search(cr, uid, [('employee_id','=',sub_nominee),('type','=','remove'),('state','not in',['draft','refuse'])])
    #nominees data
    if hol_objs:
        for a in hol_obj.browse(cr, uid, hol_objs):
                    sub_from_dt = a.date_to                                            
                    sub_to_dt=a.date_from
                    no_days=a.number_of_days_temp
                    sub_half_day=a.half_day
                    sub_half_day_sts=a.half_day_status

                    f_dt = datetime.datetime.strptime(sub_from_dt, DATETIME_FORMAT).date()
                    t_dt=datetime.datetime.strptime(sub_to_dt, DATETIME_FORMAT).date()

                    if ((from_dt==to_dt)and(to_dt==f_dt==t_dt)):

                         raise osv.except_osv(_('Warning!'),_(' %s already on leave on %s . Please nominate another person 111')%(sub_name,from_dt))


                    if ((from_dt!=to_dt)) and(no_days<=2): 

                        while from_dt <= to_dt :                         
                              new_con=self.search(cr, uid, [('date_from', '<=', date_to), ('date_to', '>=', date_from), ('employee_id', '=', sub_nominee)])
                              if new_con:
                                  raise osv.except_osv(_('Warning!'),_(' %s has/have already on leave(s) on that period  . 55555Please nominate another person')%(sub_name))
                              from_dt = from_dt + datetime.timedelta(days=1)

                    if ((f_dt!=t_dt)):                                                         
                        while t_dt <= f_dt:                                
                            if (from_dt==t_dt)or(to_dt==t_dt):
                                raise osv.except_osv(_('Warning!'),_(' %s has/have already on leave(s) on that period  . Please nominate another person 2222')%(sub_name))

                            t_dt=t_dt+datetime.timedelta(days=1)

    return True

Upvotes: 0

Views: 110

Answers (1)

Fallen
Fallen

Reputation: 4565

The error is self explanatory. There is a mismatch in the invoking parameters. onchange_sub_nominee method accepts parameters

cr, uid, ids, date_to, date_from,sub_nominee

but was invoked as,

self.onchange_sub_nominee(self, cr, uid, date_to, date_from,sub_nominee)

You need to add the value of the parameter id after uid when calling it or remove that parameter from onchange_sub_nominee definition.

Upvotes: 1

Related Questions