【问题标题】:Odoo CSV import: Found multiple matches for fieldOdoo CSV 导入:为字段找到多个匹配项
【发布时间】:2020-04-04 04:03:27
【问题描述】:

我正在使用https://github.com/tfrancoi/odoo_csv_import 将数据导入 Odoo “res.partner”模型。导入大部分字段没有问题,但是当我尝试导入字段 state_id 时会抛出此错误:“Found multiple matches for field 'State' (2 matches)”。

res_partner_mapping = {
    (........ more fields here)
    'country_id/id' : mapper.const('base.es'),
    'state_id': mapper.map_val('myStateField', my_state_dictionary),
}

这里 my_state_dictionary 只返回搜索到的 state_id,例如“AV”、“M”或“B”。

问题是 state_id 是一个组合键,所以它应该被 country_id 和 state_id 过滤。例如,“AV”是西班牙的一个州,但它在意大利也是一个不同的州,所以如果只通过 state_id 过滤它会返回 2 条记录。

字段在 Odoo 中是这样声明的:

state = fields.Many2one('country',related=city.country)

如何指定关系 related=city.country 以使用 odoo_csv_import 导入数据?

【问题讨论】:

    标签: csv import odoo odoo-13


    【解决方案1】:

    我最近遇到了同样的问题,这就是我解决它的方法:我添加了 create 函数,我正在寻找带有我的国家代码的州。

    judet_id 是我模型中的州 ID 字段,RO 是国家代码。

    @api.model
    def create(self, vals):
        state_curent = self.env['res.country.state'].search([("id","=",vals['judet_id'])])
        if(state_curent and state_curent.country_id.code != 'RO'):          
            state = self.env['res.country.state'].search([("code","=", state_curent.code), ("country_id.code","=", "RO")])
            if state:
                vals['judet_id'] = state.id
        return super().create(vals)
    

    【讨论】:

    • 请您再解释一下好吗?你能复制一下如何为 res_partner_mapping.state_id 赋值吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-05
    • 2017-02-05
    • 2019-07-12
    • 1970-01-01
    • 1970-01-01
    • 2023-01-12
    • 2012-09-01
    相关资源
    最近更新 更多