Cron 函数缺少参数
Cron function missing argument
我正在尝试制作一个 cron 函数来更改学生的状态,但它给我一个错误,我的函数有 5 个参数,但只给定了 4 个。
这是我的 class,其中包含函数 def get_age_comp:
from openerp.osv import osv, fields
from datetime import date
from dateutil.relativedelta import relativedelta
class fci_student(osv.osv):
_name = 'fci.student'
_columns = {
'photo': fields.binary(string='Photo'),
'name': fields.char(size=128, string='First Name', required=True),
'middle_name': fields.char(size=128, string='Middle Name', required=True),
'last_name': fields.char(size=128, string='Last Name', required=True),
'status': fields.selection([('under_Age', 'Under Age'), ('get_card', 'Get Card'), ('got_card', 'Got Card')],
string='Military Status'
, default='under_Age'),
# basic details
'user_id': fields.many2one('res.users', 'User'),
"birth_date": fields.date(string='Birth Date', required=True),
'gender': fields.selection([('m', 'Male'), ('f', 'Female'), ('o', 'Other')], string='Gender', required=True),
'title': fields.selection([('mr', 'Mr.'), ('ms', 'Mrs.')], string='Title'),
'Paid': fields.boolean('Paid Student'),
'nationality': fields.many2one('res.country', string='Nationality'),
'id_number': fields.char(size=64, string='ID Card Number', required=True),
'phone': fields.char(string='Phone Number', size=256, required=True),
'email_address': fields.char(string='E-mail', size=256, required=True),
'pay_amount': fields.char(size=64, string='Payment', required=True),
# Edictional details
'standard_id': fields.many2one('fci.standard', string='Standard', required=True),
'group_id': fields.many2one('fci.standard.groups',string='Groups(s)'),
'terms_id': fields.many2one('fci.terms', string='Term'),
'sit_number': fields.integer(size=128, string='Sit Number',required=True),
'subject_id':fields.many2many('fci.subject','student_sub_rel','sub_student_rel','sub_stu_id','Subjects'),
# Parent details
'parent_name': fields.char(size=128, string='Parent First Name'),
'parent_middle_name': fields.char(size=128, string='Parent First Name'),
'parent_last_name': fields.char(size=128, string='Parent First Name'),
'parent_phone': fields.integer(size=128, string='Parent Number'),
'parent_ids': fields.char(size=128, string='Parent E-mail'),
# Library details
'library_card_number': fields.char(size=64, string='Library Card Number'),
'library_card_type': fields.char(size=64, string='Library Card type'),
'number_of_books_allow': fields.char(size=64, string='Number of books allow'),
# Address details
'street_name': fields.char(size=128, string='Street', required=True),
'city_name': fields.char(size=128, string='City', required=True),
'state_name': fields.char(size=128, string='State', required=True),
'Zip': fields.char(size=128, string='Zip Code'),
'country': fields.char(size=128, string='country', required=True),
#Exams
'exam_res': fields.char(size=128, string='Results'),
'grade': fields.char(size=128, string='Results'),
'percentage': fields.char(size=128, string='Results'),
}
#the Cron function
def get_age_comp(self, cr, uid,ids ,context={}):
student_ids=self.search(cr, uid,[('gender', '=like', 'm'), ('status', '=like', 'under_Age'),
('birth_date', '<', date.today() - relativedelta(years=20))])
if student_ids:
self.write(cr, uid, student_ids, {'status': 'get_card'}, context=context)
return True
这是我的 xml 称呼:
<record id="ir_cron_actions" model="ir.cron">
<field name="name">compare</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="'fci.student'" name="model"/>
<field eval="'get_age_comp'" name="function"/>
<field eval="'()'" name="args"/>
</record>
通过删除 ID 更新您的函数,
def get_age_comp(self, cr, uid ,context={}):
student_ids=self.search(cr, uid,[('gender', '=like', 'm'), ('status', '=like', 'under_Age'),
('birth_date', '<', date.today() - relativedelta(years=20))])
if student_ids:
self.write(cr, uid, student_ids, {'status': 'get_card'}, context=context)
return True
您可以将 ids=False
作为默认参数传递,以防止回溯。
像这样写你的 cron 函数,
def get_age_comp(self, cr, uid, ids=False, context={}):
student_ids=self.search(cr, uid,[('gender', '=like', 'm'), ('status', '=like', 'under_Age'),
('birth_date', '<', date.today() - relativedelta(years=20))])
if student_ids:
self.write(cr, uid, student_ids, {'status': 'get_card'}, context=context)
return True
当您通过按钮调用您的方法时,检查方法代码很有帮助。
我正在尝试制作一个 cron 函数来更改学生的状态,但它给我一个错误,我的函数有 5 个参数,但只给定了 4 个。
这是我的 class,其中包含函数 def get_age_comp:
from openerp.osv import osv, fields
from datetime import date
from dateutil.relativedelta import relativedelta
class fci_student(osv.osv):
_name = 'fci.student'
_columns = {
'photo': fields.binary(string='Photo'),
'name': fields.char(size=128, string='First Name', required=True),
'middle_name': fields.char(size=128, string='Middle Name', required=True),
'last_name': fields.char(size=128, string='Last Name', required=True),
'status': fields.selection([('under_Age', 'Under Age'), ('get_card', 'Get Card'), ('got_card', 'Got Card')],
string='Military Status'
, default='under_Age'),
# basic details
'user_id': fields.many2one('res.users', 'User'),
"birth_date": fields.date(string='Birth Date', required=True),
'gender': fields.selection([('m', 'Male'), ('f', 'Female'), ('o', 'Other')], string='Gender', required=True),
'title': fields.selection([('mr', 'Mr.'), ('ms', 'Mrs.')], string='Title'),
'Paid': fields.boolean('Paid Student'),
'nationality': fields.many2one('res.country', string='Nationality'),
'id_number': fields.char(size=64, string='ID Card Number', required=True),
'phone': fields.char(string='Phone Number', size=256, required=True),
'email_address': fields.char(string='E-mail', size=256, required=True),
'pay_amount': fields.char(size=64, string='Payment', required=True),
# Edictional details
'standard_id': fields.many2one('fci.standard', string='Standard', required=True),
'group_id': fields.many2one('fci.standard.groups',string='Groups(s)'),
'terms_id': fields.many2one('fci.terms', string='Term'),
'sit_number': fields.integer(size=128, string='Sit Number',required=True),
'subject_id':fields.many2many('fci.subject','student_sub_rel','sub_student_rel','sub_stu_id','Subjects'),
# Parent details
'parent_name': fields.char(size=128, string='Parent First Name'),
'parent_middle_name': fields.char(size=128, string='Parent First Name'),
'parent_last_name': fields.char(size=128, string='Parent First Name'),
'parent_phone': fields.integer(size=128, string='Parent Number'),
'parent_ids': fields.char(size=128, string='Parent E-mail'),
# Library details
'library_card_number': fields.char(size=64, string='Library Card Number'),
'library_card_type': fields.char(size=64, string='Library Card type'),
'number_of_books_allow': fields.char(size=64, string='Number of books allow'),
# Address details
'street_name': fields.char(size=128, string='Street', required=True),
'city_name': fields.char(size=128, string='City', required=True),
'state_name': fields.char(size=128, string='State', required=True),
'Zip': fields.char(size=128, string='Zip Code'),
'country': fields.char(size=128, string='country', required=True),
#Exams
'exam_res': fields.char(size=128, string='Results'),
'grade': fields.char(size=128, string='Results'),
'percentage': fields.char(size=128, string='Results'),
}
#the Cron function
def get_age_comp(self, cr, uid,ids ,context={}):
student_ids=self.search(cr, uid,[('gender', '=like', 'm'), ('status', '=like', 'under_Age'),
('birth_date', '<', date.today() - relativedelta(years=20))])
if student_ids:
self.write(cr, uid, student_ids, {'status': 'get_card'}, context=context)
return True
这是我的 xml 称呼:
<record id="ir_cron_actions" model="ir.cron">
<field name="name">compare</field>
<field eval="True" name="active"/>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">minutes</field>
<field name="numbercall">-1</field>
<field eval="'fci.student'" name="model"/>
<field eval="'get_age_comp'" name="function"/>
<field eval="'()'" name="args"/>
</record>
通过删除 ID 更新您的函数,
def get_age_comp(self, cr, uid ,context={}):
student_ids=self.search(cr, uid,[('gender', '=like', 'm'), ('status', '=like', 'under_Age'),
('birth_date', '<', date.today() - relativedelta(years=20))])
if student_ids:
self.write(cr, uid, student_ids, {'status': 'get_card'}, context=context)
return True
您可以将 ids=False
作为默认参数传递,以防止回溯。
像这样写你的 cron 函数,
def get_age_comp(self, cr, uid, ids=False, context={}):
student_ids=self.search(cr, uid,[('gender', '=like', 'm'), ('status', '=like', 'under_Age'),
('birth_date', '<', date.today() - relativedelta(years=20))])
if student_ids:
self.write(cr, uid, student_ids, {'status': 'get_card'}, context=context)
return True
当您通过按钮调用您的方法时,检查方法代码很有帮助。