簡體   English   中英

Odoo attributeError:'布爾'對象沒有屬性'get'

[英]Odoo attributeError: 'bool' object has no attribute 'get'

我正在嘗試在兩個字段之間創建依賴關系。 status字段和user_id字段。 我在許多州都有這個問題。 我要的是確認問題后Assigned to出現“ Assigned to ”字段。 然后,當我將問題分配給某人時,狀態會自動從Confirmed更改為Assigned 所以我創建了這個python代碼:

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將出現以下錯誤:

     File "C:\Users\PC\git\odoo\odoo-10.0\odoo\http.py", line 935, in __call__
return self.method(*args, **kw)
     File "C:\Users\PC\git\odoo\odoo-10.0\odoo\http.py", line 506, in response_wrap
response = f(*args, **kw)
     File "C:\Users\PC\git\odoo\odoo-10.0\addons\web\controllers\main.py", line 885, in call_kw
return self._call_kw(model, method, args, kwargs)
     File "C:\Users\PC\git\odoo\odoo-10.0\addons\web\controllers\main.py", line 877, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
     File "C:\Users\PC\git\odoo\odoo-10.0\odoo\api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
     File "C:\Users\PC\git\odoo\odoo-10.0\odoo\api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
     File "C:\Users\PC\git\odoo\odoo-10.0\odoo\models.py", line 5494, in onchange
record._onchange_eval(name, field_onchange[name], result)
     File "C:\Users\PC\git\odoo\odoo-10.0\odoo\models.py", line 5393, in _onchange_eval
process(method_res)
     File "C:\Users\PC\git\odoo\odoo-10.0\odoo\models.py", line 5370, in process
if res.get('value'):
    AttributeError: 'bool' object has no attribute 'get'

謝謝您的幫助。

您需要刪除def action_upgrade_to_assigned中的返回

該錯誤可能與onchange方法有關。

return 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

通過將“ return True”固定為“ return”解決了該問題。

祝好運 !

onchange方法的返回值是錯誤的,因為Odoo期待有一個dict,並且您返回的是布爾值write方法的結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM