This question has been flagged
6 Replies
38496 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.

Avatar
Discard

Do you want to improve those views?

Best Answer

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.

Avatar
Discard

Thank you! I really liked this option

Thanks a lot irfan...you made my day

Muhammad, your proposal is really nice.

It worked on a first try for me.

But in an other case, it does not work anymore.

I try to modify a sequence.

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

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

<value eval="[('module', '=', 'account'), ('name', '=', 'sequence_payment_customer_invoice')]"/>

</function>

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

</function>

I have the following error :

"Invalid field 'module' in leaf "<osv.ExtendedLeaf: ('module', '=', 'account') on ir_sequence (ctx: )>

Best Answer

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>
Avatar
Discard

i used your answer and it works but i have 2 questions :

1 - is ID of new record must be like the old one ?

2 - is there any dangerous to delete this record ?

thanks

If model have a links with other models,

which launched as cascade delete,

then you got a problem in record

<delete id="old_module_name.identifier" model="old_module_name.model"/>

Best Answer

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.

Avatar
Discard
Best Answer

The first answer in this web page works well for me:

https://stackoverflow.com/questions/38995280/in-odoo-how-to-force-overwriting-of-a-record-rule-which-is-defined-in-a-base-mod

Avatar
Discard
Best Answer

For version 16.0

<function name="write" model="ir.model.data">
<value model="ir.model.data" search="[('module', '=', 'base'), ('name', '=', 'res_partner_rule_private_employee')]"/>
<value eval="{'noupdate': False}"/>
function>

<record id="base.res_partner_rule_private_employee" model="ir.rule">
<field name="groups" eval="[Command.set([ref('base.group_system')])]"/>
record>

<function name="write" model="ir.model.data">
<value model="ir.model.data" search="[('module', '=', 'base'), ('name', '=', 'res_partner_rule_private_employee')]"/>
<value eval="{'noupdate': True}"/>
function>

Avatar
Discard
Best Answer

Thanks a lot! @ Muhammad Irfan

It worked for me but without comments


name="write" model="ir.model.data">
name="search" model="ir.model.data">
eval="[('module', '=', 'sale'), ('name', '=', 'sale_order_personal_rule')]" />

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







Avatar
Discard