Odoo use xml data to update products

2.3k views Asked by At

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

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:

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

There are 1 answers

0
Adrian Merrall On

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.

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

and in product.product override

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