add country to sla cost

This commit is contained in:
2026-05-01 16:32:37 +02:00
parent 0f218374a7
commit 199caa2632
5 changed files with 150 additions and 10 deletions

View File

@@ -662,6 +662,79 @@ class PurchaseTradeTestCase(ModuleTestCase):
party.get_sla_cost(Mock()),
(None, None, None, None))
def test_get_sla_cost_matches_country_without_location(self):
'controller sla helper can match a destination country'
Party = Pool().get('party.party')
party = Party()
sla = Mock(id=1)
party.sla = [sla]
country = Mock(id=10)
location = Mock(country=country)
country_place = Mock(
country=country,
location=None,
cost=Decimal('12'),
mode='ppack',
currency=Mock(id=1),
unit=Mock(id=2),
)
place_model = Mock()
place_model.search.return_value = [country_place]
with patch('trytond.modules.purchase_trade.party.Pool') as PoolMock:
PoolMock.return_value.get.return_value = place_model
self.assertEqual(
party.get_sla_cost(location),
(
country_place.cost,
country_place.mode,
country_place.currency,
country_place.unit,
))
def test_get_sla_cost_prioritizes_country_location_pair(self):
'controller sla helper prefers country and location over either alone'
Party = Pool().get('party.party')
party = Party()
sla = Mock(id=1)
party.sla = [sla]
country = Mock(id=10)
location = Mock(country=country)
country_only = Mock(
country=country,
location=None,
cost=Decimal('12'),
mode='ppack',
currency=Mock(id=1),
unit=Mock(id=2),
)
location_only = Mock(
country=None,
location=location,
cost=Decimal('14'),
mode='perqt',
currency=Mock(id=3),
unit=Mock(id=4),
)
pair = Mock(
country=country,
location=location,
cost=Decimal('16'),
mode='rate',
currency=Mock(id=5),
unit=Mock(id=6),
)
place_model = Mock()
place_model.search.return_value = [country_only, location_only, pair]
with patch('trytond.modules.purchase_trade.party.Pool') as PoolMock:
PoolMock.return_value.get.return_value = place_model
self.assertEqual(
party.get_sla_cost(location),
(pair.cost, pair.mode, pair.currency, pair.unit))
def test_get_party_by_name_adds_missing_category_to_existing_party(self):
'existing parties found by automation gain the requested category when missing'
Party = Pool().get('party.party')