AttributeError:'model.name'对象没有属性'generate'(AttributeError: 'model.name' object has no attribute 'generate')
我试图从向导按钮调用一个函数,但我收到此错误:
AttributeError:'model.name'对象没有属性'generate'
AttributeError:'model.name'对象没有属性'generate'
这是我的型号代码:
class wizard(models.TransientModel): _name = 'model.name' department_id = fields.Many2one('hr.department') employee_id = fields.Many2one('hr.employee') date_from = fields.Date(string = 'Start Date', required = True) date_to = fields.Date(string = 'End Date', required = True) state = fields.Selection([('draft', 'Draft'), ('verify', 'Waiting'),('done', 'Done'),('cancel', 'Rejected'),]) def generate(self, cr, uid, ids, context=None): return self.write(cr, uid, ids, {'state': 'draft'}, context=context)在xml文件中:
<button name ="generate" type="object" string="Generate" class="oe_highlight"/>谢谢
I'm trying to call a function from a wizard button but I get this error:
AttributeError: 'model.name' object has no attribute 'generate'
AttributeError: 'model.name' object has no attribute 'generate'
this is my model code:
class wizard(models.TransientModel): _name = 'model.name' department_id = fields.Many2one('hr.department') employee_id = fields.Many2one('hr.employee') date_from = fields.Date(string = 'Start Date', required = True) date_to = fields.Date(string = 'End Date', required = True) state = fields.Selection([('draft', 'Draft'), ('verify', 'Waiting'),('done', 'Done'),('cancel', 'Rejected'),]) def generate(self, cr, uid, ids, context=None): return self.write(cr, uid, ids, {'state': 'draft'}, context=context)In the xml file:
<button name ="generate" type="object" string="Generate" class="oe_highlight"/>Thank you
最满意答案
您的代码中存在缩进问题,属于类的字段和方法必须是缩进中的下一级别。
class wizard(models.TransientModel): _name = 'model.name' department_id = fields.Many2one('hr.department') employee_id = fields.Many2one('hr.employee') date_from = fields.Date(string = 'Start Date', required = True) date_to = fields.Date(string = 'End Date', required = True) state = fields.Selection([('draft', 'Draft'), ('verify', 'Waiting'), ('done', 'Done'),('cancel', 'Rejected'),]) def generate(self, cr, uid, ids, context=None): return self.write(cr, uid, ids, {'state': 'draft'}, context=context)There is indentation issue in your code, fields and methods which are belongs to class must be the next level in indentation.
class wizard(models.TransientModel): _name = 'model.name' department_id = fields.Many2one('hr.department') employee_id = fields.Many2one('hr.employee') date_from = fields.Date(string = 'Start Date', required = True) date_to = fields.Date(string = 'End Date', required = True) state = fields.Selection([('draft', 'Draft'), ('verify', 'Waiting'), ('done', 'Done'),('cancel', 'Rejected'),]) def generate(self, cr, uid, ids, context=None): return self.write(cr, uid, ids, {'state': 'draft'}, context=context)更多推荐
发布评论