Skip to content

Commit f6ad930

Browse files
tde-banana-odooKangOl
authored andcommitted
[FIX] util.remove_field: keep field info
When removing a field, we can now keep the tracking as 'field_id' is not required anymore and tracking model holds a 'fields_info' column to keep removed field information. This globally matches the behavior implemented at `IrModelField.unlink()` as done in odoo/odoo#124182 . Note that tracking sequence is lost as it is not stored in DB (it is a field parameter available in registry) but it seems like an acceptable trade-off. Task-3345979 Part of odoo/upgrade#5239 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 41f0ce9 commit f6ad930

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/util/fields.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,34 @@ def adapter(leaf, is_or, negated):
174174
[model, fieldname],
175175
)
176176

177+
# update tracking values
178+
if column_exists(cr, "mail_tracking_value", "field_info"):
179+
cr.execute(
180+
"""
181+
SELECT id, field_description, name, ttype
182+
FROM ir_model_fields
183+
WHERE model=%s
184+
AND name=%s
185+
""",
186+
(model, fieldname),
187+
)
188+
if cr.rowcount:
189+
(field_id, field_desc_w_translation, name, ttype) = cr.fetchone()
190+
field_desc = field_desc_w_translation.get("en_US", next(iter(field_desc_w_translation.values())))
191+
fields_info = {
192+
"desc": field_desc,
193+
"name": name,
194+
"type": ttype,
195+
}
196+
cr.execute(
197+
"""
198+
UPDATE mail_tracking_value
199+
SET field_info = %s
200+
WHERE field_id = %s
201+
""",
202+
(psycopg2.extras.Json(fields_info), field_id),
203+
)
204+
177205
# remove this field from dependencies of other fields
178206
if column_exists(cr, "ir_model_fields", "depends"):
179207
cr.execute(

0 commit comments

Comments
 (0)