TypeError:无法将字典更新序列元素#0转换为序列 - Odoo v10社区迁移

时间:2017-03-18 05:03:18

标签: python openerp odoo-8 odoo-10

还有一些错误,我的模块从Odoov8迁移到Ovoo10社区

我有这个方法:

@api.model
def search_partner_seniat(self):
    """ Check vat of the partner and update iva rate
    """
    self.ensure_one()
    vat = self.vat.upper()
    res = {
        'name': _('The requested contributor does not exist'),
        'vat_subjected': False,
        'vat': vat,
        'wh_iva_agent': False,
        'wh_iva_rate': 0.0
    }

    if 'VE' in vat:
        vat = vat[2:]

    # assumption: both methods in new api style
    if self.env['res.partner'].check_vat_ve(vat):  # check_vat_ve() should be @api.model
        res = self.env['seniat.url']._dom_giver(vat)  # _dom_giver() should be @api.model
    self.write(res)

    return {
        'type': 'ir.actions.act_window',
        'res_model': 'search.info.partner.seniat',
        'view_mode': 'form',
        'view_type': 'form',
        'res_id': self.id,
        'views': [(False, 'form')],
        'target': 'new',
    }

我知道这是一个按钮,它应该(或者至少看起来)是@api.multi,但之前,当它是@api.multi时,Odoo告诉我这个方法应该是{ {1}}所以我改变了它。

我不知道,但是现在,每次点击它都会说:

api.model

有人可以对此有所了解吗?

2 个答案:

答案 0 :(得分:2)

使用@ api.multi而不是model并且您尝试使用null写入记录self.write(res),并且仅在没有id来关联当前记录的情况下使用@ api.model。例如:on Odoo create method

所以在这里我建议将代码更改为:使用 如果len(res):   self.write(RES)

答案 1 :(得分:1)

如果你想从Buttons方法返回dict,那么你必须要把它设为 @ api.multi

@api.multi
def search_partner_seniat(self):
    # do stuff
    return dict

这可能会对你有所帮助。 感谢