Trade Finance - Facility - Limit ordering

This commit is contained in:
AzureAD\SylvainDUVERNAY
2026-03-31 22:06:58 +02:00
parent aa6b3fb9ad
commit da65da79c0

View File

@@ -210,10 +210,8 @@ class FacilityLimit(ModelSQL, ModelView):
tenor = fields.Integer('Tenor (days)',
help='Maximum duration of financing from drawdown to repayment')
sequence = fields.Integer('Sequence')
path = fields.Char('Path', readonly=True,
help='Hierarchical sort key — auto-computed')
_order = [('path', 'ASC')]
_order = [('sequence', 'ASC'), ('id', 'ASC')]
is_global = fields.Function(
fields.Boolean('Global Limit',
@@ -247,59 +245,7 @@ class FacilityLimit(ModelSQL, ModelView):
if values.get('parent') and not values.get('facility'):
parent = cls(values['parent'])
values['facility'] = parent.facility.id
records = super().create(vlist)
cls._update_path(records)
return records
@classmethod
def write(cls, *args):
super().write(*args)
records = []
actions = iter(args)
for recs, _ in zip(actions, actions):
records.extend(recs)
cls._update_path(records)
@classmethod
def _update_path(cls, records):
to_write = []
for record in records:
path = cls._compute_path(record)
if record.path != path:
to_write.extend([[record], {'path': path}])
if to_write:
# Use super().write to avoid recursion
super().write(*to_write)
# Also update all descendants
all_children = []
for record in records:
all_children.extend(cls._get_descendants(record))
if all_children:
descendant_writes = []
for child in all_children:
path = cls._compute_path(child)
if child.path != path:
descendant_writes.extend([[child], {'path': path}])
if descendant_writes:
super().write(*descendant_writes)
@classmethod
def _compute_path(cls, record):
parts = []
current = record
while current:
parts.append('%07d' % (current.sequence or 0))
current = current.parent
parts.reverse()
return '/'.join(parts)
@classmethod
def _get_descendants(cls, record):
result = []
for child in record.children:
result.append(child)
result.extend(cls._get_descendants(child))
return result
return super().create(vlist)
def get_is_global(self, name):
return self.parent is None