Odoo,Python:ValueError:write()为关键字参数' context'提供了多个值。

时间:2015-12-05 21:33:28

标签: python openerp openerp-8

测试模块时出现此错误

我试图对销售订单进行两级验证 没有批准的艺术,确认订单不会完成 由销售managaer组所以这个按钮发送电子邮件,打印,确认将不会出现首先批准

Traceback (most recent call last):
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/addons/web/controllers/main.py", line 955, in exec_workflow
    return request.session.exec_workflow(model, id, signal)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 1111, in exec_workflow
    r = self.proxy('object').exec_workflow(self.db, self.uid, self.password, model, signal, id)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 879, in proxy_method
    result = dispatch_rpc(self.service_name, method, args)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/http.py", line 115, in dispatch_rpc
    result = dispatch(method, params)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/service/model.py", line 118, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/service/model.py", line 188, in exec_workflow
    return exec_workflow_cr(cr, uid, obj, signal, *args)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/service/model.py", line 182, in exec_workflow_cr
    return execute_cr(cr, uid, obj, 'signal_workflow', [res_id], signal)[res_id]
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/service/model.py", line 164, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/api.py", line 256, in wrapper
    return old_api(self, *args, **kwargs)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/models.py", line 3572, in signal_workflow
    result[res_id] = workflow.trg_validate(uid, self._name, res_id, signal, cr)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/__init__.py", line 85, in trg_validate
    return WorkflowService.new(cr, uid, res_type, res_id).validate(signal)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/service.py", line 91, in validate
    res2 = wi.validate(signal)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/instance.py", line 80, in validate
    wi.process(signal=signal, force_running=force_running, stack=stack)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 120, in process
    ok = self._split_test(activity['split_mode'], signal, stack)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 248, in _split_test
    self._join_test(t[0], t[1], stack)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 257, in _join_test
    WorkflowItem.create(self.session, self.record, activity, inst_id, stack=stack)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 95, in create
    workflow_item.process(stack=stack)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 116, in process
    if not self._execute(activity, stack):
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 162, in _execute
    returned_action = self.wkf_expr_execute(activity)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 313, in wkf_expr_execute
    return self.wkf_expr_eval_expr(activity['action'])
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/workflow/workitem.py", line 291, in wkf_expr_eval_expr
    result = eval(line, env, nocopy=True)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/tools/safe_eval.py", line 314, in safe_eval
    return eval(c, globals_dict, locals_dict)
  File "", line 1, in <module>
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/api.py", line 254, in wrapper
    return new_api(self, *args, **kwargs)
  File "/opt/bitnami/apps/odoo/lib/odoo-8.0.post20151126-py2.7.egg/openerp/api.py", line 580, in new_api
    result = method(self._model, cr, uid, self.ids, *args, **old_kwargs)
ValueError: "write() got multiple values for keyword argument 'context'" while evaluating
u"write('is_art_approved', True)"

我的python代码

from openerp.osv import osv, fields
class salesapproval_sale_order(osv.Model):
        _inherit = 'sale.order'
        _columns = {
           'state': fields.selection(
                [('cancel', 'Cancelled'),('draft', 'Draft'),('confirmed', 'Confirmed'),('exception', 'Exception'),('done', 'Done')],
                'Status', required=True, readonly=True, copy=False,
                help='* The \'Draft\' status is set when the related sales order in draft status. \
                    \n* The \'Confirmed\' status is set when the related sales order is confirmed. \
                    \n* The \'Exception\' status is set when the related sales order is set as exception. \
                    \n* The \'Done\' status is set when the sales order line has been picked. \
                    \n* The \'Cancelled\' status is set when a user cancel the sales order related.'),

}

我的xml

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="sale_view_order_form" model="ir.ui.view">
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button name="print_quotation" position="after">
<button name="approve_art" string="Approve Art" 
states="draft,sent" groups="base.group_user"/>
</button>
<button name="action_button_confirm" position="attributes">
<attribute name="states">art_approved</attribute>
</button>
<button name="print_quotation" position="attributes">
<attribute name="states">draft,sent,art_approved</attribute>
</button>
<button name="cancel" position="attributes">
<attribute name="states">draft,sent,art_approved</attribute>
</button>
</field>
</record>
</data>
</openerp>

提前致谢

3 个答案:

答案 0 :(得分:2)

您的write方法应该在字典数据结构中传递字段值,如

write({'is_art_approved', True})

而不是传递它:

write('is_art_approved', True)

在write方法中ids是必需的参数,但这取决于代码的编写方式。关于写方法的更多信息是here

Bests,

答案 1 :(得分:2)

odoo 中的

MPI_Win_lock_allcreate方法需要在数据库中写入数据的字典(键:值对)。从您的错误代码,它显示错误调用的write方法。它应该如下:

write

其中obj.write(cr, uid, ids, {'key':'value'}, context=<<your context>>) 是您需要更新数据库中数据的记录ID。

答案 2 :(得分:1)

你忘记了一些参数,或者你使用了太多参数。 write方法应包含以下参数:

 cr #used database cursor
 uid #logged in user
 ids #id from the object youŕe writing to
 data #dictionary of data that has to be written
 context #the given context