it_manager/locations: этикетки QR/EAN-13 и вкладка сервисов в дислокации.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+59
-2
@@ -1,11 +1,11 @@
|
||||
"""Формы портала для аптек."""
|
||||
"""Формы портала для аптек и сервисов/поставщиков."""
|
||||
from __future__ import annotations
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from core.models import Directory
|
||||
from .models import Pharmacy
|
||||
from .models import Location, Pharmacy
|
||||
|
||||
|
||||
class HierarchicalRegionChoiceField(forms.ModelChoiceField):
|
||||
@@ -102,3 +102,60 @@ class PortalPharmacyEditForm(forms.ModelForm):
|
||||
if user is not None and not user.has_perm('locations.manage_location_access'):
|
||||
for field in ('head_pharmacist', 'responsible_manager', 'curator'):
|
||||
self.fields.pop(field, None)
|
||||
|
||||
|
||||
class PortalVendorForm(forms.ModelForm):
|
||||
"""Создание/редактирование сервиса или поставщика (location_type=vendor)."""
|
||||
|
||||
location_region = HierarchicalRegionChoiceField(
|
||||
label=_('Город/район'),
|
||||
empty_label=_('— Выберите регион —'),
|
||||
required=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = Location
|
||||
fields = (
|
||||
'name', 'location_region',
|
||||
'street', 'house_number', 'building', 'apartment',
|
||||
'comments', 'is_active',
|
||||
)
|
||||
widgets = {
|
||||
'name': forms.TextInput(attrs={
|
||||
'class': 'input',
|
||||
'placeholder': 'Вайтер Юг',
|
||||
'required': True,
|
||||
}),
|
||||
'street': forms.TextInput(attrs={'class': 'input'}),
|
||||
'house_number': forms.TextInput(attrs={'class': 'input'}),
|
||||
'building': forms.TextInput(attrs={'class': 'input'}),
|
||||
'apartment': forms.TextInput(attrs={'class': 'input'}),
|
||||
'comments': forms.Textarea(attrs={'class': 'input', 'rows': 2}),
|
||||
'is_active': forms.CheckboxInput(),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['name'].required = True
|
||||
self.fields['location_region'].widget.attrs['class'] = 'input'
|
||||
for optional in ('street', 'house_number', 'building', 'apartment', 'comments'):
|
||||
self.fields[optional].required = False
|
||||
|
||||
def clean_name(self):
|
||||
name = (self.cleaned_data.get('name') or '').strip()
|
||||
if not name:
|
||||
raise forms.ValidationError(_('Укажите название.'))
|
||||
qs = Location.objects.filter(location_type='vendor', name__iexact=name)
|
||||
if self.instance and self.instance.pk:
|
||||
qs = qs.exclude(pk=self.instance.pk)
|
||||
if qs.exists():
|
||||
raise forms.ValidationError(_('Такой сервис/поставщик уже есть.'))
|
||||
return name
|
||||
|
||||
def save(self, commit=True):
|
||||
obj = super().save(commit=False)
|
||||
obj.location_type = 'vendor'
|
||||
obj.name = (obj.name or '').strip()
|
||||
if commit:
|
||||
obj.save()
|
||||
return obj
|
||||
|
||||
Reference in New Issue
Block a user