From aa39da8461695ce279bf0242b53b085df0e52f58 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Sun, 26 May 2019 11:00:48 +0200 Subject: [PATCH] [IMP] add_fields: Consider corner edges and >= v12 * In v12, ir.model.data goes in another way. * Don't fail if ir.model.data exists. --- openupgradelib/openupgrade.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/openupgradelib/openupgrade.py b/openupgradelib/openupgrade.py index 8c629a1c..1140366b 100644 --- a/openupgradelib/openupgrade.py +++ b/openupgradelib/openupgrade.py @@ -1887,7 +1887,9 @@ def add_fields(env, field_spec): NOTE: This only works in >=v8 and is not needed in >=v12, as now Odoo always add the XML-ID entry: https://github.com/odoo/odoo/blob/9201f92a4f29a53a014b462469f27b32dca8fc5a/ - odoo/addons/base/models/ir_model.py#L794-L802 + odoo/addons/base/models/ir_model.py#L794-L802, but you can still call + this method for consistency and for avoiding to know the internal PG + column type. :param: field_spec: List of tuples with the following expected elements for each tuple: @@ -1954,18 +1956,22 @@ def add_fields(env, field_spec): ) field_id = env.cr.fetchone()[0] # Add ir.model.data entry - if not module: + if not module or version_info[0] >= 12: continue name1 = 'field_%s_%s' % (model_name.replace('.', '_'), field_name) - logged_query( - env.cr, """ - INSERT INTO ir_model_data ( - name, date_init, date_update, module, model, res_id - ) VALUES ( - %s, (now() at time zone 'UTC'), (now() at time zone 'UTC'), - %s, %s, %s - )""", (name1, module, 'ir.model.fields', field_id), - ) + try: + logged_query( + env.cr, """ + INSERT INTO ir_model_data ( + name, date_init, date_update, module, model, res_id + ) VALUES ( + %s, (now() at time zone 'UTC'), (now() at time zone 'UTC'), + %s, %s, %s + )""", (name1, module, 'ir.model.fields', field_id), + ) + except IntegrityError: + # Do not fail if already present + pass def update_module_moved_fields(