Mtm
This commit is contained in:
@@ -134,6 +134,32 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
|||||||
strategy.get_mtm(line, Decimal('3')),
|
strategy.get_mtm(line, Decimal('3')),
|
||||||
Decimal('225.00'))
|
Decimal('225.00'))
|
||||||
|
|
||||||
|
@with_transaction()
|
||||||
|
def test_signed_strategy_mtm_follows_valuation_direction(self):
|
||||||
|
'strategy MTM follows purchase/sale valuation sign'
|
||||||
|
Valuation = Pool().get('valuation.valuation')
|
||||||
|
strategy = Mock(get_mtm=Mock(return_value=Decimal('349167.53')))
|
||||||
|
line = Mock()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
Valuation._signed_strategy_mtm(
|
||||||
|
{'type': 'pur. priced', 'amount': Decimal('-190686.15'),
|
||||||
|
'quantity': Decimal('4237.47')},
|
||||||
|
strategy, line),
|
||||||
|
Decimal('-349167.53'))
|
||||||
|
self.assertEqual(
|
||||||
|
Valuation._signed_strategy_mtm(
|
||||||
|
{'type': 'sale priced', 'amount': Decimal('349167.53'),
|
||||||
|
'quantity': Decimal('4237.47')},
|
||||||
|
strategy, line),
|
||||||
|
Decimal('349167.53'))
|
||||||
|
self.assertEqual(
|
||||||
|
Valuation._signed_strategy_mtm(
|
||||||
|
{'type': 'pur. priced', 'amount': Decimal('0'),
|
||||||
|
'quantity': Decimal('0')},
|
||||||
|
strategy, line),
|
||||||
|
Decimal('-349167.53'))
|
||||||
|
|
||||||
@with_transaction()
|
@with_transaction()
|
||||||
def test_purchase_line_charter_conditions_inherit_header_when_empty(self):
|
def test_purchase_line_charter_conditions_inherit_header_when_empty(self):
|
||||||
'purchase line uses header charter conditions when it has no line terms'
|
'purchase line uses header charter conditions when it has no line terms'
|
||||||
|
|||||||
@@ -375,6 +375,18 @@ class ValuationBase(ModelSQL):
|
|||||||
def _supports_strategy_mtm(values):
|
def _supports_strategy_mtm(values):
|
||||||
return values and values.get('type') in {'pur. priced', 'sale priced'}
|
return values and values.get('type') in {'pur. priced', 'sale priced'}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _signed_strategy_mtm(cls, values, strategy, line):
|
||||||
|
mtm = strategy.get_mtm(line, values['quantity'])
|
||||||
|
if mtm is None:
|
||||||
|
return mtm
|
||||||
|
amount = values.get('amount')
|
||||||
|
if amount:
|
||||||
|
return abs(mtm) if amount > 0 else -abs(mtm)
|
||||||
|
if values.get('type') in {'pur. priced', 'pur. efp'}:
|
||||||
|
return -abs(mtm)
|
||||||
|
return abs(mtm)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _get_basis_component_total(record):
|
def _get_basis_component_total(record):
|
||||||
getter = getattr(record, '_get_basis_component_price', None)
|
getter = getattr(record, '_get_basis_component_price', None)
|
||||||
@@ -526,7 +538,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if line.mtm and cls._supports_strategy_mtm(values):
|
if line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in line.mtm:
|
for strat in line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, line)
|
||||||
values['mtm'] = strat.get_mtm(line, values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
@@ -544,7 +556,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if line.mtm and cls._supports_strategy_mtm(values):
|
if line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in line.mtm:
|
for strat in line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, line)
|
||||||
values['mtm'] = strat.get_mtm(line,values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
@@ -567,7 +579,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if line.mtm and cls._supports_strategy_mtm(values):
|
if line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in line.mtm:
|
for strat in line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, line)
|
||||||
values['mtm'] = strat.get_mtm(line,values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
@@ -602,7 +614,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if sl_line.mtm and cls._supports_strategy_mtm(values):
|
if sl_line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in line.mtm:
|
for strat in line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sl_line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sl_line)
|
||||||
values['mtm'] = strat.get_mtm(sl_line,values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, sl_line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
@@ -624,7 +636,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if sl_line.mtm and cls._supports_strategy_mtm(values):
|
if sl_line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in sl_line.mtm:
|
for strat in sl_line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sl_line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sl_line)
|
||||||
values['mtm'] = strat.get_mtm(sl_line,values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, sl_line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
@@ -750,7 +762,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if sale_line.mtm and cls._supports_strategy_mtm(values):
|
if sale_line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in sale_line.mtm:
|
for strat in sale_line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sale_line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sale_line)
|
||||||
values['mtm'] = strat.get_mtm(sale_line, values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, sale_line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
@@ -767,7 +779,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if sale_line.mtm and cls._supports_strategy_mtm(values):
|
if sale_line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in sale_line.mtm:
|
for strat in sale_line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sale_line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sale_line)
|
||||||
values['mtm'] = strat.get_mtm(sale_line, values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, sale_line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
@@ -790,7 +802,7 @@ class ValuationBase(ModelSQL):
|
|||||||
if sale_line.mtm and cls._supports_strategy_mtm(values):
|
if sale_line.mtm and cls._supports_strategy_mtm(values):
|
||||||
for strat in sale_line.mtm:
|
for strat in sale_line.mtm:
|
||||||
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sale_line)
|
values['mtm_price'] = cls._get_strategy_mtm_price(strat, sale_line)
|
||||||
values['mtm'] = strat.get_mtm(sale_line, values['quantity'])
|
values['mtm'] = cls._signed_strategy_mtm(values, strat, sale_line)
|
||||||
values['strategy'] = strat
|
values['strategy'] = strat
|
||||||
|
|
||||||
if values:
|
if values:
|
||||||
|
|||||||
Reference in New Issue
Block a user