I'm trying to create a dependence between two fields. The status
field and the user_id
field. I have this issue with many states. What I want is that when the issue is confirmed the field Assigned to
appears. Then when I assign the issue to someone, the state changes automatically from Confirmed
to Assigned
. So I created this python code:
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'})
And this is the xml
code:
<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>
When I run this code and change user_id
this error appears:
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'
Thank you for your help.
您需要删除def action_upgrade_to_assigned中的返回
Probably, the error is related to the onchange method.
return self.write({'state':'assigned'}) => This process return a boolean result.
I had the same sitution when I was doing this:
@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
The problem was solved by fixing "return True" as "return" .
Good Luck !
onchange方法的返回值是错误的,因为Odoo期待有一个dict,并且您返回的是布尔值write方法的结果。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.