错误说
ValueError: "global name 'cr' is not defined" while evaluating
u'set_to_draft_reservation()'
在方法中创建变量cr并为其分配self.env.cr 定义它 错误说 变量cr的多值
Odoo Server Error
Traceback (most recent call last):
File "/opt/odoo/openerp/http.py", line 543, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/opt/odoo/openerp/http.py", line 580, in dispatch
result = self._call_function(**self.params)
File "/opt/odoo/openerp/http.py", line 316, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/opt/odoo/openerp/service/model.py", line 118, in wrapper
return f(dbname, *args, **kwargs)
File "/opt/odoo/openerp/http.py", line 313, in checked_call
return self.endpoint(*a, **kw)
File "/opt/odoo/openerp/http.py", line 809, in __call__
return self.method(*args, **kw)
File "/opt/odoo/openerp/http.py", line 409, in response_wrap
response = f(*args, **kw)
File "/opt/odoo/addons/web/controllers/main.py", line 944, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/opt/odoo/addons/web/controllers/main.py", line 936, in _call_kw
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)
File "/opt/odoo/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/openerp/api.py", line 372, in old_api
result = method(recs, *args, **kwargs)
File "/opt/odoo/addons/hotel_reservation/models/hotel_reservation.py", line 518, in create
return super(HotelReservation, self).create(vals)
File "/opt/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/api.py", line 508, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/opt/odoo/addons/mail/mail_thread.py", line 381, in create
thread_id = super(mail_thread, self).create(cr, uid, values, context=context)
File "/opt/odoo/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/openerp/api.py", line 372, in old_api
result = method(recs, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 4100, in create
record = self.browse(self._create(old_vals))
File "/opt/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/openerp/api.py", line 508, in new_api
result = method(self._model, cr, uid, *args, **old_kwargs)
File "/opt/odoo/openerp/models.py", line 4326, in _create
self.create_workflow(cr, user, [id_new], context=context)
File "/opt/odoo/openerp/api.py", line 268, in wrapper
return old_api(self, *args, **kwargs)
File "/opt/odoo/openerp/models.py", line 3546, in create_workflow
workflow.trg_create(uid, self._name, res_id, cr)
File "/opt/odoo/openerp/workflow/__init__.py", line 73, in trg_create
return WorkflowService.new(cr, uid, res_type, res_id).create()
File "/opt/odoo/openerp/workflow/service.py", line 81, in create
WorkflowInstance.create(self.session, self.record, wkf_id)
File "/opt/odoo/openerp/workflow/instance.py", line 54, in create
WorkflowItem.create(session, record, activity, instance_id, stack)
File "/opt/odoo/openerp/workflow/workitem.py", line 95, in create
workflow_item.process(stack=stack)
File "/opt/odoo/openerp/workflow/workitem.py", line 116, in process
if not self._execute(activity, stack):
File "/opt/odoo/openerp/workflow/workitem.py", line 162, in _execute
returned_action = self.wkf_expr_execute(activity)
File "/opt/odoo/openerp/workflow/workitem.py", line 313, in wkf_expr_execute
return self.wkf_expr_eval_expr(activity['action'])
File "/opt/odoo/openerp/workflow/workitem.py", line 291, in wkf_expr_eval_expr
result = eval(line, env, nocopy=True)
File "/opt/odoo/openerp/tools/safe_eval.py", line 314, in safe_eval
return eval(c, globals_dict, locals_dict)
File "", line 1, in <module>
File "/opt/odoo/openerp/api.py", line 266, in wrapper
return new_api(self, *args, **kwargs)
File "/opt/odoo/addons/hotel_reservation/models/hotel_reservation.py", line 321, in set_to_draft_reservation
self.delete_workflow(cr, uid, [reservation.id])
ValueError: "global name 'cr' is not defined" while evaluating
u'set_to_draft_reservation()'
导致错误的方法
@api.multi
def set_to_draft_reservation(self):
for reservation in self:
reservation.write({'state':'draft'})
# Deleting the existing instance of workflow for PO
self.delete_workflow(self._cr, self._uid, [reservation.id])
self.create_workflow(cr, uid, [reservation.id])
return True