AttributeError:'model.name'对象没有属性'generate'(AttributeError: 'model.name

编程入门 行业动态 更新时间:2024-10-09 11:22:03
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)

更多推荐

本文发布于:2023-07-27 08:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:属性   对象   model   AttributeError   object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!