it_manager: сортировка локаций по коду и полный список в селекте.
Аптеки А1…А70/П… вместо сортировки по адресу; убрать лимит 50 в searchable-select. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -590,3 +590,51 @@ class PharmacyHistoryTests(TestCase):
|
||||
p.carbonio_sync_status = 'synced'
|
||||
p.save(update_fields=['carbonio_sync_status'])
|
||||
self.assertEqual(PharmacyHistory.objects.filter(pharmacy=p).count(), 0)
|
||||
|
||||
|
||||
class LocationSortKeyTests(TestCase):
|
||||
"""Селекты IT: офис сверху, аптеки по коду А1…А70, не по адресу."""
|
||||
|
||||
def test_pharmacies_sorted_by_object_code(self):
|
||||
from apps.locations.models.base import Location, location_sort_key
|
||||
|
||||
org_type, _ = DirectoryType.objects.get_or_create(
|
||||
code='organization', defaults={'name': 'Организация'},
|
||||
)
|
||||
region_type, _ = DirectoryType.objects.get_or_create(
|
||||
code='region', defaults={'name': 'Регион'},
|
||||
)
|
||||
region = Directory.objects.create(directory_type=region_type, code='od-sort', name='Одесса-sort')
|
||||
org_a = Directory.objects.create(
|
||||
directory_type=org_type, code='aks-sort', name='АКС',
|
||||
extra_data={'mail_prefix': 'a'},
|
||||
)
|
||||
org_p = Directory.objects.create(
|
||||
directory_type=org_type, code='pent-sort', name='Пентальфа',
|
||||
extra_data={'mail_prefix': 'p'},
|
||||
)
|
||||
office = Location.objects.create(
|
||||
location_type='office', location_region=region,
|
||||
street='Канатная', house_number='78', is_active=True,
|
||||
)
|
||||
p68 = Pharmacy.objects.create(
|
||||
organization=org_a, location_region=region,
|
||||
pharmacy_number=68, location_type='pharmacy',
|
||||
street='Танцюри', house_number='16', is_active=True,
|
||||
)
|
||||
p3 = Pharmacy.objects.create(
|
||||
organization=org_a, location_region=region,
|
||||
pharmacy_number=3, location_type='pharmacy',
|
||||
street='Ясная', house_number='1', is_active=True,
|
||||
)
|
||||
p1 = Pharmacy.objects.create(
|
||||
organization=org_p, location_region=region,
|
||||
pharmacy_number=1, location_type='pharmacy',
|
||||
street='Академическая', house_number='2', is_active=True,
|
||||
)
|
||||
ordered = sorted([p68, office, p1, p3], key=location_sort_key)
|
||||
self.assertEqual(ordered[0].pk, office.pk)
|
||||
self.assertEqual(
|
||||
[location_sort_key(x)[1:3] for x in ordered[1:]],
|
||||
[(0, 3), (0, 68), (1, 1)], # А3, А68, П1
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user