Demurrage
This commit is contained in:
@@ -3347,26 +3347,26 @@ class StatementOfFacts(ModelSQL, ModelView):
|
||||
|
||||
@fields.depends('shipment', 'charter_party', 'applied_condition')
|
||||
def on_change_shipment(self):
|
||||
if self.shipment and self.shipment.charter_party and not self.charter_party:
|
||||
self.charter_party = self.shipment.charter_party
|
||||
self._set_default_applied_condition()
|
||||
|
||||
@fields.depends('charter_party', 'applied_condition')
|
||||
@fields.depends('shipment', 'charter_party', 'applied_condition')
|
||||
def on_change_charter_party(self):
|
||||
self._set_default_applied_condition()
|
||||
|
||||
def _set_default_applied_condition(self):
|
||||
if self.applied_condition:
|
||||
condition_ids = self.get_applied_conditions()
|
||||
applied_condition_id = getattr(self.applied_condition, 'id', None)
|
||||
if applied_condition_id in condition_ids:
|
||||
return
|
||||
conditions = getattr(self.charter_party, 'conditions', None) or []
|
||||
if len(conditions) == 1:
|
||||
self.applied_condition = conditions[0]
|
||||
self.applied_condition = None
|
||||
if len(condition_ids) == 1:
|
||||
self.applied_condition = condition_ids[0]
|
||||
|
||||
def get_owner_charter_conditions(self, name=None):
|
||||
if self.charter_party:
|
||||
return ShipmentIn._unique_condition_ids(self.charter_party.conditions)
|
||||
if self.shipment:
|
||||
return self.shipment.get_owner_charter_conditions(name)
|
||||
if self.charter_party:
|
||||
return ShipmentIn._unique_condition_ids(self.charter_party.conditions)
|
||||
return []
|
||||
|
||||
def get_purchase_charter_conditions(self, name=None):
|
||||
|
||||
@@ -1457,6 +1457,35 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
sof._applied_compensation_amount(), Decimal('-12000.00'))
|
||||
self.assertEqual(sof.compensation_type, 'demurrage')
|
||||
|
||||
@with_transaction()
|
||||
def test_sof_available_conditions_include_shipment_contracts(self):
|
||||
'sof applied condition choices include owner, purchase and sale terms'
|
||||
Sof = Pool().get('sof.statement')
|
||||
sof = Sof()
|
||||
sof.charter_party = None
|
||||
sof.shipment = Mock(
|
||||
get_owner_charter_conditions=Mock(return_value=[1]),
|
||||
get_purchase_charter_conditions=Mock(return_value=[2]),
|
||||
get_sale_charter_conditions=Mock(return_value=[3]))
|
||||
|
||||
self.assertEqual(sof.get_applied_conditions(), [1, 2, 3])
|
||||
|
||||
@with_transaction()
|
||||
def test_sof_default_applied_condition_can_use_purchase_terms(self):
|
||||
'sof default applied condition can come from purchase without charter'
|
||||
Sof = Pool().get('sof.statement')
|
||||
sof = Sof()
|
||||
sof.charter_party = None
|
||||
sof.shipment = Mock(
|
||||
charter_party=None,
|
||||
get_owner_charter_conditions=Mock(return_value=[]),
|
||||
get_purchase_charter_conditions=Mock(return_value=[12]),
|
||||
get_sale_charter_conditions=Mock(return_value=[]))
|
||||
|
||||
sof.on_change_shipment()
|
||||
|
||||
self.assertEqual(sof.applied_condition, 12)
|
||||
|
||||
@with_transaction()
|
||||
def test_sof_laytime_start_reads_structured_condition_rule(self):
|
||||
'sof laytime start reads the structured event and offset'
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
<form>
|
||||
<notebook>
|
||||
<page string="Contract Conditions" id="cs">
|
||||
<label name="charter_party"/>
|
||||
<field name="charter_party"/>
|
||||
<field name="charter_party" invisible="1"/>
|
||||
<field name="applied_conditions" invisible="1" colspan="4"/>
|
||||
<newline/>
|
||||
<label name="applied_condition"/>
|
||||
<field name="applied_condition"/>
|
||||
<newline/>
|
||||
|
||||
Reference in New Issue
Block a user