Odoo Help

0

How can I update a record stored with the attribute noupdate="1"?

By
Robin Chatfield
on 2/27/15, 3:46 AM 3,682 views

I have a module that got the noupdate="1" attribute added to all views, actions and menuitems. Now those records can't be upgraded, even after the xml file in the module has been corrected. I'm already using the module, and would rather not have to reinstall it and lose the data.

Some options I've considered:

Find where the noupdate attribute is stored in the database, and change it for my records. Does anyone know how this can be done?

Delete all the records from the database. Tried it, and it works. Unfortunately the db crashes before I've goten all the records, and then I have to restore and am back to square one.

Export the data, uninstall module, reinstall, and import the data again.

Do you want to improve those views?

Mansi Kariya (mka)
on 2/27/15, 3:50 AM
2
Ivan
On 2/27/15, 4:51 AM

The noupdate is stored in the ir_model_data table.  Just change the noupdate column to FALSE for the record (search it using the XML ID against the name column).  This will allow you to make "noupdate" records to be updateable in the future.

If you want to just change something in the records created by the data XML, I would recommend that you just change it via the application, e.g. for ir.ui.view --> through Settings >> Technical >> User Interface >> Views.

6
Habib
On 4/5/16, 6:17 PM

Records that are created in xml files also create an external identifier which is named [module name].[id]

When noupdate="1" is specified in the xml data file, then the external identifier created has a field called noupdate set to True. Once this happens, it is impossible to update a record using xml.

You can find the external identifier in Technical -> Sequences and Identifiers -> External Identifiers. Find the id of the record you're looking for and uncheck the noupdate field. Once this is done, you can update the record using your xml data file.

I had a requirement for a module to update existing records which were previously set to noupdate. This had to be done in xml. To achieve this I did the following in the data file (new_module_data.xml)

1.I deleted the record

2. I re-created the record using the original identifier

<openerp>
<data noupdate="0">
<delete id="old_module_name.identifier" model="old_module_name.model"/>
<record id="old_module_name.identifier" model="old_module_name.model">
...
</record>
</data>
</openerp>
0
Muhammad Irfan
On 4/10/17, 3:55 AM

Other answers are okay, but if you want to do it using a XML file inside a module, you can try to do the following (change the model based on your needs):

<function name="write" model="ir.model.data">

            <!-- First we need to find the record...-->

            <function name="search" model="ir.model.data">

                <value

                  eval="[('module', '=', 'purchase'), ('name', '=', 'purchase_order_comp_rule')]"

                  />

            </function>

           <!-- ...and temporarily set the noupdate field to False-->

            <value eval="{'noupdate': False}" />

        </function>

       <!-- Get our main job done, i.e. modify the domain_force field of a record -->

        <record id="purchase.purchase_order_comp_rule" model="ir.rule">

            <field name="domain_force">[('company_id','=',user.company_id.id)]</field>

        </record>

       <!-- (Optional) Time to clean our dirty hand, set the previously noupdate False to True again -->

        <function name="write" model="ir.model.data">

            <function name="search" model="ir.model.data">

                <value

                  eval="[('module', '=', 'purchase'), ('name', '=', 'purchase_order_comp_rule')]"

                  />

            </function>

            <value eval="{'noupdate': True}" />

        </function>


Hope it helps!

*Sorry i'm not using the code tag to put the code above, for unknown reasons it behaves strangely.

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)

Stats

Asked: 2/27/15, 3:46 AM
Seen: 3682 times
Last updated: 4/10/17, 3:55 AM