Odoo attributeError:'bool'对象没有属性'get'

时间:2017-12-21 10:30:42

标签: python openerp odoo-10

我正在尝试在两个字段之间创建依赖关系。 19/12/2018 08:13 AM 29/11/2017 08:13 AM 30/10/2016 08:13 PM 字段和status字段。我和许多州有这个问题。我想要的是,当问题得到确认后,字段user_id就会出现。然后,当我将问题分配给某人时,状态会自动从Assigned to更改为Confirmed。所以我创建了这个python代码:

Assigned

这是class ProjectIssue(models.Model): _name = "project.issue" _description = "Project Issue" _inherit = "project.issue" state = fields.Selection([('new', 'New'), ('feedback', 'Feedback'), ('acknowledged', 'Acknowledged'), ('confirmed', 'Confirmed'), ('assigned', 'Assigned'), ('testing', 'Testing'), ('resolved', 'Resolved'), ('closed', 'Closed'), ], string='Issue Status', default='new') def action_back_to_new(self): return self.write({'state': 'new'}) def action_upgrade_to_feedback(self): return self.write({'state': 'feedback'}) def action_back_to_feedback(self): return self.write({'state':'feedback'}) def action_acknowledge(self): return self.write({'state':'acknowledged'}) def action_confirm(self): return self.write({'state':'confirmed'}) @api.onchange('user_id') def action_upgrade_to_assigned(self): return self.write({'state':'assigned'}) 代码:

xml

当我运行此代码并更改 <record id="project_issue_form_view_2" model="ir.ui.view"> <field name="name">project.issue.form</field> <field name="model">project.issue</field> <field name="inherit_id" ref="project_issue.project_issue_form_view"/> <field name="arch" type="xml"> <field name="stage_id" position="replace"> <button name="action_confirm" string="Confirm" type="object" states="acknowledged" class="btn-primary"/> <button name="action_back_to_feedback" string="Back to Feedback" type="object" states="acknowledged" class="btn-primary"/> <button name="action_back_to_new" string="Back to new" type="object" states="feedback" class="btn-primary"/> <button name="action_acknowledge" string="Acknowledge" type="object" states="feedback" class="btn-primary"/> <button name="action_upgrade_to_feedback" string="Upgrade to feedback" type="object" states="new" class="btn-primary"/> <field name="state" widget="statusbar"/> </field> <field name="priority" position="replace"> <field name="ipriority"/> </field> <field name="user_id" position="replace"> <field name="user_id" attrs="{'invisible': [('state', 'in', ['new', 'feedback', 'acknowledged'])]}"/> </field> </field> </record> </field> 时,会出现此错误:

user_id

感谢您的帮助。

3 个答案:

答案 0 :(得分:0)

您需要在def action_upgrade_to_assigned

中删除return

答案 1 :(得分:0)

该错误可能与onchange方法有关。

返回self.write({'state':'assigned'}) =>此过程返回布尔值结果。

当我这样做时,我的处境是相同的:

    @api.onchange('date_to')
    def _onchange_date_to(self):
        date_from = self.date_from
        date_to = self.date_to
        if not (date_from or date_to):
            return True

此问题已通过将“返回True” 固定为“返回” 来解决。

祝你好运!

答案 2 :(得分:0)

onchange方法的返回值是错误的,因为Odoo期待一个字典,并且您返回的是布尔值的write方法的结果。