我正在尝试从向导按钮调用函数,但是我收到此错误:
AttributeError:'model.name'对象没有属性'generate'
AttributeError:'model.name'对象没有属性'generate'
这是我的型号代码:
<button name ="generate" type="object" string="Generate" class="oe_highlight"/>
在xml文件中:
html5
谢谢
答案 0 :(得分:0)
您的代码中存在缩进问题,属于类的字段和方法必须是缩进的下一级别。
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)