Demurrage

This commit is contained in:
2026-06-03 14:30:16 +02:00
parent 5763ca64a5
commit adcce718fd
6 changed files with 121 additions and 50 deletions

View File

@@ -197,6 +197,8 @@ class PurchaseTradeTestCase(ModuleTestCase):
sof = Sof()
sof.applied_condition = Mock(
laytime_allowed=None,
laytime_start_offset=None,
laytime_start_offset_unit=None,
turn_time=Decimal('6'),
turn_time_unit='hours',
rates=[
@@ -215,13 +217,15 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(sof.compensation_type, 'demurrage')
@with_transaction()
def test_sof_laytime_start_reads_text_clause_turn_time(self):
'sof laytime start reads NOR plus hours from the condition text'
def test_sof_laytime_start_reads_structured_condition_rule(self):
'sof laytime start reads the structured event and offset'
Sof = Pool().get('sof.statement')
sof = Sof()
sof.applied_condition = Mock(
turn_time=None,
laytime_start='NOR + 6 hours')
laytime_start_event='notice_of_readiness',
laytime_start_offset=Decimal('6'),
laytime_start_offset_unit='hours',
turn_time=None)
sof.notice_of_readiness_time = datetime.datetime(2026, 6, 1, 2, 0)
self.assertEqual(
@@ -229,11 +233,11 @@ class PurchaseTradeTestCase(ModuleTestCase):
datetime.datetime(2026, 6, 1, 8, 0))
@with_transaction()
def test_sof_laytime_end_reads_hoses_disconnected_clause(self):
'sof laytime end can use hoses disconnected from the condition text'
def test_sof_laytime_end_reads_structured_condition_rule(self):
'sof laytime end reads the structured end event'
Sof = Pool().get('sof.statement')
sof = Sof()
sof.applied_condition = Mock(laytime_end='Hoses disconnected')
sof.applied_condition = Mock(laytime_end_event='hoses_disconnected')
sof.end_pumping = datetime.datetime(2026, 6, 1, 12, 0)
sof.hoses_disconnected = datetime.datetime(2026, 6, 1, 13, 0)
@@ -241,6 +245,31 @@ class PurchaseTradeTestCase(ModuleTestCase):
sof._applied_laytime_end(),
datetime.datetime(2026, 6, 1, 13, 0))
@with_transaction()
def test_sof_laytime_ignores_free_text_clauses(self):
'sof laytime calculation ignores contractual free text fields'
Sof = Pool().get('sof.statement')
sof = Sof()
sof.applied_condition = Mock(
laytime_start_event='arrival',
laytime_start_offset=Decimal('1'),
laytime_start_offset_unit='hours',
laytime_end_event='end_pumping',
laytime_start='NOR + 6 hours',
laytime_end='Hoses disconnected',
turn_time=None)
sof.arrival_time = datetime.datetime(2026, 6, 1, 3, 0)
sof.notice_of_readiness_time = datetime.datetime(2026, 6, 1, 2, 0)
sof.end_pumping = datetime.datetime(2026, 6, 1, 12, 0)
sof.hoses_disconnected = datetime.datetime(2026, 6, 1, 13, 0)
self.assertEqual(
sof._applied_laytime_start(),
datetime.datetime(2026, 6, 1, 4, 0))
self.assertEqual(
sof._applied_laytime_end(),
datetime.datetime(2026, 6, 1, 12, 0))
@with_transaction()
def test_sof_header_date_time_values_sync_to_datetime(self):
'sof header date and time fields build the technical datetime value'