fix(inventory): enforce consistent date format in document forms and views
- Add explicit date input format '%Y-%m-%d' to WriteOffDocumentForm and IncomingDocumentForm - Disable localization for date fields to ensure yyyy-MM-dd format is used - Set initial date value to current date in WriteOffDocumentCreateView's get_initial method - Restrict warehouse queryset to active warehouses in forms initialization - Improve date widget consistency by adding format parameter to DateInput widgets
This commit is contained in:
@@ -243,18 +243,16 @@ class WriteOffDocumentForm(forms.ModelForm):
|
||||
fields = ['warehouse', 'date', 'notes']
|
||||
widgets = {
|
||||
'warehouse': forms.Select(attrs={'class': 'form-control'}),
|
||||
'date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
|
||||
'date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}, format='%Y-%m-%d'),
|
||||
'notes': forms.Textarea(attrs={'class': 'form-control', 'rows': 3, 'placeholder': 'Примечания к документу'}),
|
||||
}
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['warehouse'].queryset = Warehouse.objects.filter(is_active=True)
|
||||
|
||||
# Устанавливаем дату по умолчанию - сегодня
|
||||
if not self.initial.get('date'):
|
||||
from django.utils import timezone
|
||||
self.initial['date'] = timezone.now().date()
|
||||
|
||||
# Отключаем локализацию для поля date, чтобы использовать формат yyyy-MM-dd
|
||||
self.fields['date'].input_formats = ['%Y-%m-%d']
|
||||
|
||||
# Если есть склад по умолчанию - предвыбираем его
|
||||
if not self.initial.get('warehouse'):
|
||||
@@ -346,7 +344,7 @@ class IncomingDocumentForm(forms.ModelForm):
|
||||
fields = ['warehouse', 'date', 'receipt_type', 'supplier_name', 'notes']
|
||||
widgets = {
|
||||
'warehouse': forms.Select(attrs={'class': 'form-control'}),
|
||||
'date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
|
||||
'date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}, format='%Y-%m-%d'),
|
||||
'receipt_type': forms.Select(attrs={'class': 'form-control'}),
|
||||
'supplier_name': forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'Наименование поставщика'}),
|
||||
'notes': forms.Textarea(attrs={'class': 'form-control', 'rows': 3, 'placeholder': 'Примечания к документу'}),
|
||||
@@ -355,6 +353,9 @@ class IncomingDocumentForm(forms.ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.fields['warehouse'].queryset = Warehouse.objects.filter(is_active=True)
|
||||
|
||||
# Отключаем локализацию для поля date, чтобы использовать формат yyyy-MM-dd
|
||||
self.fields['date'].input_formats = ['%Y-%m-%d']
|
||||
|
||||
# Если есть склад по умолчанию - предвыбираем его
|
||||
if not self.initial.get('warehouse'):
|
||||
|
||||
Reference in New Issue
Block a user