Add Fixed type component

This commit is contained in:
2026-05-31 15:56:18 +02:00
parent 83f7e43a6e
commit fcd809a3e3
8 changed files with 222 additions and 68 deletions

View File

@@ -80,6 +80,29 @@ class PurchaseTradeTestCase(ModuleTestCase):
strategy.get_mtm(line, Decimal('10')),
Decimal('250.00'))
@with_transaction()
def test_get_mtm_uses_fixed_pricing_component(self):
'get_mtm values fixed components like a constant price curve'
Strategy = Pool().get('mtm.strategy')
strategy = Strategy()
strategy.scenario = Mock(
valuation_date='2026-03-29',
use_last_price=True,
)
strategy.currency = Mock()
strategy.components = [Mock(
price_source_type='fixed',
price_index=None,
price_matrix=None,
get_price=Mock(return_value=Decimal('75')),
ratio=Decimal('100'),
)]
line = Mock(unit=Mock())
self.assertEqual(
strategy.get_mtm(line, Decimal('3')),
Decimal('225.00'))
@with_transaction()
def test_add_physical_lot_defaults_hidden_premium_and_chunk_key(self):
'add physical lot works when hidden tree fields are not loaded'
@@ -182,6 +205,28 @@ class PurchaseTradeTestCase(ModuleTestCase):
valuation_module.Valuation._get_strategy_mtm_price(strategy, line),
Decimal('40.0000'))
def test_get_strategy_mtm_price_uses_fixed_pricing_component(self):
'strategy mtm price uses fixed components like constant price curves'
strategy = Mock(
scenario=Mock(
valuation_date='2026-03-29',
use_last_price=True,
),
currency=Mock(),
)
strategy.components = [Mock(
price_source_type='fixed',
price_index=None,
price_matrix=None,
get_price=Mock(return_value=Decimal('75')),
ratio=Decimal('50'),
)]
line = Mock(unit=Mock())
self.assertEqual(
valuation_module.Valuation._get_strategy_mtm_price(strategy, line),
Decimal('37.5000'))
def test_sale_line_is_unmatched_checks_lot_links(self):
'sale line unmatched helper ignores empty matches and detects linked purchases'
sale_line = Mock()
@@ -1941,6 +1986,39 @@ class PurchaseTradeTestCase(ModuleTestCase):
self.assertEqual(component.get_calendar(), calendar)
def test_pricing_component_fixed_returns_flat_price(self):
'fixed pricing returns the component flat price'
Component = Pool().get('pricing.component')
component = Component()
component.price_source_type = 'fixed'
component.fixed_price = Decimal('125.25')
currency = Mock(id=1)
component.fixed_currency = currency
self.assertEqual(
component.get_price(
datetime.date(2026, 4, 1), Mock(), currency, False),
Decimal('125.2500'))
def test_pricing_component_fixed_converts_currency(self):
'fixed pricing converts from component currency to requested currency'
Component = Pool().get('pricing.component')
component = Component()
component.price_source_type = 'fixed'
component.fixed_price = Decimal('100')
component.fixed_currency = Mock(id=1)
target_currency = Mock(id=2)
currency_model = Mock(
_get_rate=Mock(return_value={
component.fixed_currency.id: Decimal('1.2')}))
with patch('trytond.modules.purchase_trade.pricing.Pool') as PricingPool:
PricingPool.return_value.get.return_value = currency_model
price = component.get_price(
datetime.date(2026, 4, 1), Mock(), target_currency, False)
self.assertEqual(price, Decimal('120.0000'))
def test_sale_and_purchase_trader_operator_domains_use_explicit_categories(self):
'sale and purchase trader/operator fields are filtered by TRADER/OPERATOR categories'
Sale = Pool().get('sale.sale')