Skip to content

Commit 415fc94

Browse files
aj-fuentesKangOl
andcommitted
[FIX] util/fields: also convert inherits fields
When converting fields types we need to continue to inherits. Before we avoided that because the column may be missing but it leads to situations where custom manual fields are not updated properly. For example if we add a custom manual field in `product.packaging.x_pdesc` related to `product_id.description`. Without this patch the upgrade `x_pdesc` is still of `ttype=text`. With this patch: ``` test_14_15=> select id,model,name,state,related,related_field_id,ttype from ir_model_fields where name like 'x\_%' or (model like 'product.%' and name='description') +------+-------------------+-------------+--------+-----------------------------+------------------+-------+ | id | model | name | state | related | related_field_id | ttype | |------+-------------------+-------------+--------+-----------------------------+------------------+-------| | 3068 | product.packaging | x_pdesc | manual | product_id.description | 2635 | html | | 2516 | product.template | description | base | <null> | <null> | html | | 2635 | product.product | description | base | product_tmpl_id.description | <null> | html | +------+-------------------+-------------+--------+-----------------------------+------------------+-------+ ``` There are many specific fixes to update manual related fields to `product.product.description`. Also fix missing function parameter. `convert_field_to_html` expects a cursor as first parameter. closes #34 Signed-off-by: Christophe Simonis (chs) <[email protected]> Co-authored-by: "Christophe Simonis" <[email protected]>
1 parent 51bccea commit 415fc94

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/util/fields.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -488,23 +488,24 @@ def rename_field(cr, model, old, new, update_references=True, domain_adapter=Non
488488
def convert_field_to_html(cr, model, field, skip_inherit=()):
489489
_validate_model(model)
490490
table = table_of_model(cr, model)
491-
jsonb_column = column_type(cr, table, field) == "jsonb"
492-
if jsonb_column:
493-
query = """
494-
WITH html_values AS (
495-
SELECT id, jsonb_object_agg(t.key, {2}) AS value
496-
FROM "{0}", jsonb_each_text("{1}") AS t
497-
WHERE {{parallel_filter}}
498-
GROUP BY id
499-
)
500-
UPDATE "{0}"
501-
SET "{1}" = h.value
502-
FROM html_values AS h
503-
WHERE "{0}".id = h.id
504-
""".format(table, field, pg_text2html("t.value"))
505-
else:
506-
query = 'UPDATE "{0}" SET "{1}" = {2} WHERE "{1}" IS NOT NULL'.format(table, field, pg_text2html(field))
507-
parallel_execute(cr, explode_query_range(cr, query, table=table))
491+
if column_exists(cr, table, field): # only exists for list-based inherits (not for dict-based)
492+
jsonb_column = column_type(cr, table, field) == "jsonb"
493+
if jsonb_column:
494+
query = """
495+
WITH html_values AS (
496+
SELECT id, jsonb_object_agg(t.key, {2}) AS value
497+
FROM "{0}", jsonb_each_text("{1}") AS t
498+
WHERE {{parallel_filter}}
499+
GROUP BY id
500+
)
501+
UPDATE "{0}"
502+
SET "{1}" = h.value
503+
FROM html_values AS h
504+
WHERE "{0}".id = h.id
505+
""".format(table, field, pg_text2html("t.value"))
506+
else:
507+
query = 'UPDATE "{0}" SET "{1}" = {2} WHERE "{1}" IS NOT NULL'.format(table, field, pg_text2html(field))
508+
parallel_execute(cr, explode_query_range(cr, query, table=table))
508509

509510
# Update translations
510511
if table_exists(cr, "ir_translation"):
@@ -532,8 +533,7 @@ def convert_field_to_html(cr, model, field, skip_inherit=()):
532533
[field, model],
533534
)
534535
for inh in for_each_inherit(cr, model, skip_inherit):
535-
if not inh.via:
536-
convert_field_to_html(inh.model, field, skip_inherit=skip_inherit)
536+
convert_field_to_html(cr, inh.model, field, skip_inherit=skip_inherit)
537537

538538

539539
def convert_field_to_property(

0 commit comments

Comments
 (0)