Trade Finance - TF Facility - Order limits
This commit is contained in:
@@ -210,13 +210,16 @@ class FacilityLimit(ModelSQL, ModelView):
|
|||||||
tenor = fields.Integer('Tenor (days)',
|
tenor = fields.Integer('Tenor (days)',
|
||||||
help='Maximum duration of financing from drawdown to repayment')
|
help='Maximum duration of financing from drawdown to repayment')
|
||||||
sequence = fields.Integer('Sequence')
|
sequence = fields.Integer('Sequence')
|
||||||
|
path = fields.Char('Path', readonly=True,
|
||||||
|
help='Hierarchical sort key — auto-computed')
|
||||||
|
|
||||||
|
_order = [('path', 'ASC')]
|
||||||
|
|
||||||
is_global = fields.Function(
|
is_global = fields.Function(
|
||||||
fields.Boolean('Global Limit',
|
fields.Boolean('Global Limit',
|
||||||
states={'invisible': Bool(Eval('parent'))},
|
states={'invisible': Bool(Eval('parent'))},
|
||||||
depends=['parent']),
|
depends=['parent']),
|
||||||
'get_is_global')
|
'get_is_global')
|
||||||
level = fields.Function(fields.Integer('Level'), 'get_level')
|
|
||||||
display_name = fields.Function(fields.Char('Name'), 'get_display_name')
|
display_name = fields.Function(fields.Char('Name'), 'get_display_name')
|
||||||
|
|
||||||
haircuts = fields.One2Many('trade_finance.facility_limit_haircut', 'limit',
|
haircuts = fields.One2Many('trade_finance.facility_limit_haircut', 'limit',
|
||||||
@@ -244,21 +247,69 @@ class FacilityLimit(ModelSQL, ModelView):
|
|||||||
if values.get('parent') and not values.get('facility'):
|
if values.get('parent') and not values.get('facility'):
|
||||||
parent = cls(values['parent'])
|
parent = cls(values['parent'])
|
||||||
values['facility'] = parent.facility.id
|
values['facility'] = parent.facility.id
|
||||||
return super().create(vlist)
|
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
|
||||||
|
|
||||||
def get_is_global(self, name):
|
def get_is_global(self, name):
|
||||||
return self.parent is None
|
return self.parent is None
|
||||||
|
|
||||||
def get_level(self, name):
|
def get_display_name(self, name):
|
||||||
level = 0
|
level = 0
|
||||||
current = self
|
current = self
|
||||||
while current.parent:
|
while current.parent:
|
||||||
level += 1
|
level += 1
|
||||||
current = current.parent
|
current = current.parent
|
||||||
return level
|
|
||||||
|
|
||||||
def get_display_name(self, name):
|
|
||||||
level = self.get_level(None)
|
|
||||||
prefix = '— ' * level
|
prefix = '— ' * level
|
||||||
return prefix + (self.name or '')
|
return prefix + (self.name or '')
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,4 @@
|
|||||||
<field name="amount"/>
|
<field name="amount"/>
|
||||||
<field name="tenor"/>
|
<field name="tenor"/>
|
||||||
<field name="is_global"/>
|
<field name="is_global"/>
|
||||||
<field name="name" invisible="1"/>
|
|
||||||
<field name="level" invisible="1"/>
|
|
||||||
</tree>
|
</tree>
|
||||||
|
|||||||
Reference in New Issue
Block a user