繁体   English   中英

Openerp-如何在“创建”函数中调用自定义函数?

[英]Openerp- How to call custom function inside the “create” function?

请帮助我解决这个问题,我有一个用于检查输入的验证条件的函数,我想在“ create”函数内将其称为嵌套函数。 一旦以正常方式调用它,它就会不断给我参数不匹配的错误。 请帮我。 在create函数中,我这样称呼它

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)

功能是这样的,

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

该错误不言自明。 调用参数不匹配。 onchange_sub_nominee方法接受参数

cr, uid, ids, date_to, date_from,sub_nominee

但被引用为

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

调用时,您需要在uid之后添加参数id的值,或从onchange_sub_nominee定义中删除该参数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM