Delete tree width records when field is set multiple times

There is no unique constraint so the method to set width should not rely on the
unicity of the field per screen size.

Closes #13997
This commit is contained in:
Cédric Krier committed 2025-05-04 08:40:40 +02:00
1 parent 39ddf8b838
commit a69b2b6b69
1 file changed
+8 -3
+8 -3
View File
@@ -548,11 +548,14 @@ class ViewTreeWidth(
])
fields = fields.copy()
to_save = []
to_save, to_delete = [], []
for tree_width in records:
if tree_width.screen_width == screen_width:
tree_width.width = fields.pop(tree_width.field)
to_save.append(tree_width)
if tree_width.field in fields:
tree_width.width = fields.pop(tree_width.field)
to_save.append(tree_width)
else:
to_delete.append(tree_width)
for name, width in fields.items():
to_save.append(cls(
@@ -564,6 +567,8 @@ class ViewTreeWidth(
if to_save:
cls.save(to_save)
if to_delete:
cls.delete(to_delete)
@classmethod
def reset_width(cls, model, width):