python - 类型错误 : write() got an unexpected keyword argument 'context' - Odoo v8 to Odoo v10 community

标签 python odoo odoo-8 odoo-10

我继承了res.partner类,我有这两个方法:

jour_id = fields.Many2one('account.journal', string='Journal', required=False,
    help="Default journal for damaged invoices")
acc_id = fields.Many2one('account.account', string='Account', 
    help="Default account used for invoices and lines from damaged invoices")
printer_fiscal = fields.Boolean(string='Manages fiscal printer',
    help='Indicates that the company can operate a fiscal printer')

@api.model
def create(self, vals): 
    """ To create a new record,
    adds a Boolean field to true
    indicates that the partner is a company
    """
    #if context is None:
        #context = {}
    ctx = self._context.copy()
    ctx.update({'create_company': True})
    return super(ResCompany, self).create(vals) 

@api.model
def write(self, values): 
    """ To write a new record,
    adds a Boolean field to true
    indicates that the partner is a company
    """
    #if context is None:
        #context = {}
    ctx = self._context.copy()
    ctx.update({'create_company': True})
    return super(ResCompany, self).write(values)

这两个字段,由createwrite这两个函数更新或创建。

但是当我尝试其中任何一个时,通过编辑公司,它抛给我这个:

Traceback (most recent call last):
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 862, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/kristian/odoov10/odoo-10.0rc1c-20161005/odoo/addons/web/controllers/main.py", line 854, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 679, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/home/kristian/.virtualenvs/odoov10/lib/python2.7/site-packages/odoo-10.0rc1c_20161005-py2.7.egg/odoo/api.py", line 664, in call_kw_model
result = method(recs, *args, **kwargs)
TypeError: write() got an unexpected keyword argument 'context'

我认为是因为这个 ctx = self._context.copy() 但我在 v10 上看到其他方法以这种方式声明,我不知道是否应该删除

对此有什么想法吗?

最佳答案

你需要在write方法中使用@api.multi装饰器。

@api.multi
def write(self, values): 
    """ To write a new record,
    adds a Boolean field to true
    indicates that the partner is a company
    """
    #if context is None:
        #context = {}
    ctx = dict(self._context or {})
    ctx.update({'create_company': True})
    return super(ResCompany, self.with_context(ctx)).write(values)

这里的“Self”是一个记录集,您不能在 write 方法中使用 @api.one

您可以从下面的链接中找到 2 个装饰器之间的区别。

When to use api.one and api.multi in odoo | openerp?

关于python - 类型错误 : write() got an unexpected keyword argument 'context' - Odoo v8 to Odoo v10 community,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43025682/

相关文章:

docker - 服务 'odoo' 无法从 docker 构建

database - Odoo 数据库登录问题?

odoo - 基于其他选择框的选择框填充

python - 如何在 python 列表中追加字段值并忽略 None 值

python - 如何修复 IndexError : invalid index to scalar variable

python - 简单的 Python 正则表达式查找模式

python - 如何解决 psycopg2.ProgrammingError : column reference "account_analytic_id" is ambiguous in odoo

python - 如何在以下功能中使用电子邮件模板?

python - 如何运行协程而不等待它?

Python IOError : [Errno 13] Permission denied 错误