From a69b2b6b69a3d745ffc2f12b89f15e8ab24c16ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 4 May 2025 08:40:40 +0200 Subject: [PATCH] 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 --- trytond/trytond/ir/ui/view.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/trytond/trytond/ir/ui/view.py b/trytond/trytond/ir/ui/view.py index 7760ad86b4..03632b9b37 100644 --- a/trytond/trytond/ir/ui/view.py +++ b/trytond/trytond/ir/ui/view.py @@ -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):