Price linked currency
This commit is contained in:
@@ -5536,6 +5536,65 @@ description</t></is></c>
|
||||
('price_date', '<=', '2026-04-10'),
|
||||
], order=[('price_date', 'DESC')])
|
||||
|
||||
def test_price_get_price_per_qt_converts_linked_currency_to_main_currency(self):
|
||||
'price curve values in linked currency are normalized to main currency'
|
||||
Price = Pool().get('price.price')
|
||||
price = Price()
|
||||
usd = SimpleNamespace(id=1)
|
||||
price.price_currency = usd
|
||||
price.enable_linked_currency = True
|
||||
price.linked_currency = SimpleNamespace(factor=Decimal('0.01'))
|
||||
price.price_unit = SimpleNamespace()
|
||||
|
||||
uom_model = Mock(compute_qty=Mock(return_value=1))
|
||||
currency_model = Mock()
|
||||
|
||||
def get_model(name):
|
||||
if name == 'product.uom':
|
||||
return uom_model
|
||||
if name == 'currency.currency':
|
||||
return currency_model
|
||||
return Mock()
|
||||
|
||||
with patch('trytond.modules.price.price.Pool') as PricePool:
|
||||
PricePool.return_value.get.side_effect = get_model
|
||||
result = price.get_price_per_qt(Decimal('72.5'), Mock(), usd)
|
||||
|
||||
self.assertEqual(result, Decimal('0.7250'))
|
||||
currency_model._get_rate.assert_not_called()
|
||||
|
||||
def test_price_get_price_applies_linked_currency_conversion(self):
|
||||
'market price lookup applies linked currency conversion'
|
||||
Price = Pool().get('price.price')
|
||||
price = Price()
|
||||
price.id = 42
|
||||
usd = SimpleNamespace(id=1)
|
||||
price.price_currency = usd
|
||||
price.enable_linked_currency = True
|
||||
price.linked_currency = SimpleNamespace(factor=Decimal('0.01'))
|
||||
price.price_unit = SimpleNamespace()
|
||||
price.price_values = [Mock()]
|
||||
price_value = Mock(price_value=Decimal('72.5'))
|
||||
price_value_model = Mock(
|
||||
search=Mock(return_value=[price_value]))
|
||||
uom_model = Mock(compute_qty=Mock(return_value=1))
|
||||
|
||||
def get_model(name):
|
||||
if name == 'price.price_value':
|
||||
return price_value_model
|
||||
if name == 'product.uom':
|
||||
return uom_model
|
||||
if name == 'currency.currency':
|
||||
return Mock()
|
||||
return Mock()
|
||||
|
||||
with patch('trytond.modules.price.price.Pool') as PricePool:
|
||||
PricePool.return_value.get.side_effect = get_model
|
||||
result = price.get_price(
|
||||
datetime.date(2026, 4, 10), Mock(), usd, last=True)
|
||||
|
||||
self.assertEqual(result, Decimal('0.7250'))
|
||||
|
||||
def test_pricing_component_matrix_prefers_specific_line_over_generic(self):
|
||||
'matrix pricing keeps generic lines as fallback below matching lines'
|
||||
Component = Pool().get('pricing.component')
|
||||
|
||||
Reference in New Issue
Block a user