Pricing default
This commit is contained in:
@@ -2653,6 +2653,93 @@ class PurchaseTradeTestCase(ModuleTestCase):
|
||||
|
||||
self.assertIsNone(pricing.price_component)
|
||||
|
||||
def test_pricing_component_default_triggers_copy_first_purchase_component(self):
|
||||
'new purchase components inherit trigger values from the first component'
|
||||
Component = Pool().get('pricing.component')
|
||||
pricing_period = Mock(id=21)
|
||||
application_period = Mock(id=22)
|
||||
first_component = Mock(triggers=[
|
||||
Mock(
|
||||
pricing_period=pricing_period,
|
||||
from_p=datetime.date(2026, 4, 1),
|
||||
to_p=datetime.date(2026, 4, 5),
|
||||
average=True,
|
||||
last=False,
|
||||
application_period=application_period,
|
||||
from_a=datetime.date(2026, 5, 1),
|
||||
to_a=datetime.date(2026, 5, 5),
|
||||
),
|
||||
])
|
||||
|
||||
with patch.object(Component, 'search',
|
||||
return_value=[first_component]) as search:
|
||||
values = Component._default_trigger_values(line=10)
|
||||
|
||||
search.assert_called_once_with(
|
||||
[('line', '=', 10)], order=[('id', 'ASC')], limit=1)
|
||||
self.assertEqual(values, [{
|
||||
'pricing_period': 21,
|
||||
'from_p': datetime.date(2026, 4, 1),
|
||||
'to_p': datetime.date(2026, 4, 5),
|
||||
'average': True,
|
||||
'last': False,
|
||||
'application_period': 22,
|
||||
'from_a': datetime.date(2026, 5, 1),
|
||||
'to_a': datetime.date(2026, 5, 5),
|
||||
}])
|
||||
|
||||
def test_pricing_component_create_inherits_first_sale_component_triggers(self):
|
||||
'component create copies triggers from the first sale line component'
|
||||
Component = Pool().get('pricing.component')
|
||||
first_component = Mock(triggers=[
|
||||
Mock(
|
||||
pricing_period=Mock(id=21),
|
||||
from_p=datetime.date(2026, 4, 1),
|
||||
to_p=datetime.date(2026, 4, 5),
|
||||
average=True,
|
||||
last=True,
|
||||
application_period=None,
|
||||
from_a=None,
|
||||
to_a=None,
|
||||
),
|
||||
])
|
||||
|
||||
with patch.object(Component, 'search',
|
||||
return_value=[first_component]) as search, patch(
|
||||
'trytond.modules.purchase_trade.pricing.super') as super_mock:
|
||||
Component.create([{'sale_line': 10, 'price_source_type': 'curve'}])
|
||||
|
||||
search.assert_called_once_with(
|
||||
[('sale_line', '=', 10)], order=[('id', 'ASC')], limit=1)
|
||||
created_values = super_mock.return_value.create.call_args.args[0][0]
|
||||
self.assertEqual(created_values['triggers'], [('create', [{
|
||||
'pricing_period': 21,
|
||||
'from_p': datetime.date(2026, 4, 1),
|
||||
'to_p': datetime.date(2026, 4, 5),
|
||||
'average': True,
|
||||
'last': True,
|
||||
'application_period': None,
|
||||
'from_a': None,
|
||||
'to_a': None,
|
||||
}])])
|
||||
|
||||
def test_pricing_component_create_keeps_explicit_triggers(self):
|
||||
'component create does not replace triggers already provided'
|
||||
Component = Pool().get('pricing.component')
|
||||
explicit_triggers = [('create', [{'average': False}])]
|
||||
|
||||
with patch.object(Component, 'search') as search, patch(
|
||||
'trytond.modules.purchase_trade.pricing.super') as super_mock:
|
||||
Component.create([{
|
||||
'line': 10,
|
||||
'price_source_type': 'curve',
|
||||
'triggers': explicit_triggers,
|
||||
}])
|
||||
|
||||
search.assert_not_called()
|
||||
created_values = super_mock.return_value.create.call_args.args[0][0]
|
||||
self.assertIs(created_values['triggers'], explicit_triggers)
|
||||
|
||||
def test_pricing_component_must_belong_to_pricing_owner(self):
|
||||
'pricing rows reject components from another purchase or sale line'
|
||||
Pricing = Pool().get('pricing.pricing')
|
||||
|
||||
Reference in New Issue
Block a user