[IMP] base: make ir.model.data use access fields

Apparently some "core objects" used to have a pair of
fields (date_init, date_update) which predate the current access
fields (hopefully anyway, the genesis of both is lost to time so we
can only speculate).

odoo/odoo#34988 removed them on constrains & relations and left them
on ir.model.data, but they do seem redundant with the regular access
fields which *are* enabled on ir.model.data.

* removes the date_init/date_update fields
* converts the one bit of code which did set those to set
  create_date/write_date
* add a default value on the columns, to ensure create_date is
  properly set even from SQL queries
* use create_date/write_date in the view
* adds setting those columns to a bunch of raw SQL queries which were
  missing them (also updates the queries some to merge the literal
  values into the queries as it seems unnecessary to interpolate
  e.g. a boolean literal)

Builds on and closes odoo/odoo#50516 as that's why I started looking
into it, and that fix is in this branch as well.

closes odoo/odoo#50661

Related: odoo/upgrade#1213
Related: odoo/enterprise#10772
Signed-off-by: Xavier Morel (xmo) <xmo@odoo.com>
This commit is contained in:
Xavier Morel
2020-05-27 06:16:01 +00:00
parent 2a0638079e
commit 148f3dabc9
3 changed files with 7 additions and 11 deletions
+2 -4
View File
@@ -84,13 +84,11 @@ CREATE TABLE ir_module_module_dependency (
CREATE TABLE ir_model_data (
id serial NOT NULL,
create_uid integer,
create_date timestamp without time zone,
write_date timestamp without time zone,
create_date timestamp without time zone DEFAULT (now() at time zone 'UTC'),
write_date timestamp without time zone DEFAULT (now() at time zone 'UTC'),
write_uid integer,
noupdate boolean DEFAULT False,
name varchar NOT NULL,
date_init timestamp without time zone,
date_update timestamp without time zone,
module varchar NOT NULL,
model varchar NOT NULL,
res_id integer,
+3 -5
View File
@@ -1790,8 +1790,6 @@ class IrModelData(models.Model):
module = fields.Char(default='', required=True)
res_id = fields.Many2oneReference(string='Record ID', help="ID of the target record in the database", model_field='model')
noupdate = fields.Boolean(string='Non Updatable', default=False)
date_update = fields.Datetime(string='Update Date', default=fields.Datetime.now)
date_init = fields.Datetime(string='Init Date', default=fields.Datetime.now)
reference = fields.Char(string='Reference', compute='_compute_reference', readonly=True, store=False)
_sql_constraints = [
@@ -1988,12 +1986,12 @@ class IrModelData(models.Model):
# NOTE: this method is overriden in web_studio; if you need to make another
# override, make sure it is compatible with the one that is there.
def _build_update_xmlids_query(self, sub_rows, update):
rowf = "(%s, %s, %s, %s, %s, now() at time zone 'UTC', now() at time zone 'UTC')"
rowf = "(%s, %s, %s, %s, %s)"
return """
INSERT INTO ir_model_data (module, name, model, res_id, noupdate, date_init, date_update)
INSERT INTO ir_model_data (module, name, model, res_id, noupdate)
VALUES {rows}
ON CONFLICT (module, name)
DO UPDATE SET date_update=(now() at time zone 'UTC') {where}
DO UPDATE SET write_date=(now() at time zone 'UTC') {where}
""".format(
rows=", ".join([rowf] * len(sub_rows)),
where="WHERE NOT ir_model_data.noupdate" if update else "",
+2 -2
View File
@@ -466,8 +466,8 @@
<field name="module"/>
<field name="name"/>
<field name="noupdate"/>
<field name="date_update" />
<field name="date_init" />
<field name="write_date" />
<field name="create_date" />
</group>
<group>
<field name="display_name"/>