Odoo使用xml数据来更新产品

时间:2022-05-05 20:24:03

Hi I have to update a product data with a new module that add some features to product.product model but when I try to install the new module data it give me a error because its trying to create a new product and not to update the existing product

嗨,我必须使用为product.product模型添加一些功能的新模块更新产品数据,但是当我尝试安装新模块数据时,它会给我一个错误,因为它试图创建一个新产品而不是更新现有产品产品

example: product record

例如:产品记录

<record model="product.product" id="product_product_11109613400">
    <field name="list_price">0.07388597</field>
    <field name="standard_price">0.0739</field>
    <field name="default_code">11109613400</field>
    <field name="name">LAMP</field>
    <field name="categ_id" ref="product_category_categoria_06"/>
    <field name="uom_po_id" ref="product.product_uom_unit"/>
    <field name="uom_id" ref="product.product_uom_unit"/>
    <field name="sale_ok" eval="False"/>
    <field name="purchase_ok" eval="True"/>
</record>

the update xml:

更新xml:

<record model="product.product" id="product_product_11109613400">
    <field name="hazard_ids" eval="[(4, ref('product_safety_advice_r4'))]"/>
</record>

1 个解决方案

#1


1  

I would look in ir_model_data and see what the name field is set to for the original create and that might give you a clue as to why the update is failing. If that doesn't work you could use a function that runs when the module is installed/updated.

我会查看ir_model_data并查看原始创建的名称字段设置的内容,这可能会为您提供更新失败原因的线索。如果这不起作用,您可以使用在安装/更新模块时运行的函数。

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <function model="product.product" name="do_foo" />
    </data>
</openerp>

and in product.product override

并在product.product覆盖

@api.model
def do_foo(self):
    ...

#1


1  

I would look in ir_model_data and see what the name field is set to for the original create and that might give you a clue as to why the update is failing. If that doesn't work you could use a function that runs when the module is installed/updated.

我会查看ir_model_data并查看原始创建的名称字段设置的内容,这可能会为您提供更新失败原因的线索。如果这不起作用,您可以使用在安装/更新模块时运行的函数。

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <function model="product.product" name="do_foo" />
    </data>
</openerp>

and in product.product override

并在product.product覆盖

@api.model
def do_foo(self):
    ...