TypeError(repr(o)+“不是JSON可序列化的"")-Odoo v8 [英] TypeError(repr(o) + " is not JSON serializable") - Odoo v8

查看:245
本文介绍了TypeError(repr(o)+“不是JSON可序列化的"")-Odoo v8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此方法,它需要与Odoo v8上的发票关联的文档.

I have this method, which calls for a document associated with an invoice on Odoo v8.

@api.multi
def button_generate_wh_doc(self):
context = self._context
partner = self.env['res.partner']
res = {}
for inv in self:
    view_id = self.env['ir.ui.view'].search([
        ('name', '=', 'account.invoice.wh.iva.customer')])
    context = self.env.context.copy()
    context.update({'domain':[(
        ('invoice_id','=',inv.id),
        ('type','=',inv.type),
        ('default_partner_id','=', partner._find_accounting_partner(
            inv.partner_id).id),
        ('default_name' ,'=', inv.name or inv.number),
        ('view_id' ,'=', view_id))]})
res = {
        'name': _('Withholding vat customer'),
        'type': 'ir.actions.act_window',
        'res_model': 'account.wh.iva',
        'view_type': 'form',
        'view_id': False,
        'view_mode': 'form',
        'nodestroy': True,
        'target': 'current',
        'domain': "[('type', '=', '" + inv.type + "')]",
        'context': context
    }
return res

但是每次我从按钮中调用它时,我都会被抛出:

But everytime I call this from button it throws me this:

Traceback (most recent call last):
File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 544, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 595, in dispatch
return self._json_response(result)
File "/home/kristian/odoov8/odoo-8.0-20161017/openerp/http.py", line 533, in _json_response
body = simplejson.dumps(response)
File "/usr/local/lib/python2.7/dist-packages/simplejson/__init__.py", line 366, in dumps
return _default_encoder.encode(obj)
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 269, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 348, in iterencode
return _iterencode(o, 0)
File "/usr/local/lib/python2.7/dist-packages/simplejson/encoder.py", line 246, in default
raise TypeError(repr(o) + " is not JSON serializable")

我已阅读答案

但是我仍然不确定,这可能是因为domain我正在研究此问题的原因吗?

But I'm still not sure about it, it could be because of the domain where I'm working this on?

推荐答案

您在res中传递的域必须是tuplelist而不是stringtuplelist下面的代码:

The domain you passing in res has to be list of tuple and not list of tuple of string, check below code :

@api.multi
def button_generate_wh_doc(self):
    context = self._context
    partner = self.env['res.partner']
    res = {}
    for inv in self:
        view_id = self.env['ir.ui.view'].search([
            ('name', '=', 'account.invoice.wh.iva.customer')])
        context = self.env.context.copy()
        context.update({
            'domain':[
                ('invoice_id','=',inv.id),
                ('type','=',inv.type),
                ('default_partner_id','=', partner._find_accounting_partner(inv.partner_id).id),
                ('default_name' ,'=', inv.name or inv.number),
                ('view_id' ,'=', view_id[0].id)
            ]
        })
    return {
        'name': _('Withholding vat customer'),
        'type': 'ir.actions.act_window',
        'res_model': 'account.wh.iva',
        'view_type': 'form',
        'view_id': False,
        'view_mode': 'form',
        'target': 'current',
        'domain': [('type', '=', inv.type )],
        'context': context,
    }

这篇关于TypeError(repr(o)+“不是JSON可序列化的"")-Odoo v8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆