Skip to Content
Menu
This question has been flagged
2 Replies
5070 Views

Hello,

Is there any option to change record create_date and create_uid via ORM.
In my use case i need to change those values, updating via self.env.cr.execute seems to lag from time to time.

Avatar
Discard

You can override odoo create method: https://goo.gl/4BkizH

Best Answer

Use sudo() function in ORM.

sudo([user=SUPERUSER])

Returns a new version of this recordset attached to the provided
user.

By default this returns a `SUPERUSER` recordset, where access control
and record rules are bypassed.

.. note::
Using `sudo` could cause data access to cross the boundaries of
record rules, possibly mixing records that are meant to be
isolated (e.g. records from different companies in multi-company
environments).

It may lead to un-intuitive results in methods which select one
record among many - for example getting the default company, or
selecting a Bill of Materials.

.. note::
Because the record rules and access control will have to be
re-evaluated, the new recordset will not benefit from the current
environment's data cache, so later data access may incur extra
delays while re-fetching from the database.
 

In Default it will be superuser. If you need to be as a regular user, then use sudo(user_id).func()
example: env['model_name'].sudo(user_id).create({})

Avatar
Discard