Cron函数缺少参数

时间:2015-04-11 03:55:50

标签: python xml cron odoo openerp-8

我正在尝试创建一个cron函数来改变学生的状态,但它给了我一个错误,我的函数需要5个参数而且只有4个。

这是我的类,其中包含函数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>

2 个答案:

答案 0 :(得分:2)

删除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

答案 1 :(得分:1)

您可以将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

通过按钮调用方法时检查方法代码很有帮助。