0
私はこの問題を解決するのを手伝ってください。 入力の検証条件を確認するための関数があり、その関数を入れ子関数として "作成"関数の中で呼び出す必要があります。通常の方法で呼び出すと、パラメータの不一致エラーが発生し続けます。私を助けてください。私はこのOpenerp- "作成"機能の中でカスタム関数を呼び出す方法は?
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
あなたは完全なコードを提供できますか?呼び出しにパラメータの不一致があるように聞こえます。 – Fallen
もちろん、質問を更新しました。特定のフィールドの変更時機能として正常に機能する関数自体。 –
あなたの関数宣言に 'uid'と' date_to'の間にパラメータ 'ids'があり、それは呼び出しにはありません。 'self.on_change ... 'でメソッドを呼び出すと、' self.onchange_sub_nominee(cr、uid、ids、date_to、date_from、sub_nominee) 'のように別の' self'パラメータをブラケットに入れる必要はありません。 –