refactor(inventory): remove individual writeoff views and templates, shift to document-based writeoffs

- Remove WriteOffForm from forms.py and add comment directing to WriteOffDocumentForm
- Update navigation templates to remove writeoff links and sections
- Add 'Сумма' column to sale list with multiplication filter
- Delete writeoff-related templates (list, form, confirm delete)
- Add 'multiply' filter to inventory_filters.py for calculations
- Comment out writeoff URLs in urls.py, keeping WriteOff model for automatic creation
- Remove WriteOff views from __init__.py and delete writeoff.py view file

This change simplifies writeoff management by removing direct individual writeoff operations and enforcing use of WriteOffDocument for all writeoffs, with WriteOff records created automatically upon document processing.
This commit is contained in:
2025-12-27 01:04:41 +03:00
parent 1eaee7de5e
commit 44d115b356
11 changed files with 59 additions and 535 deletions

View File

@@ -68,41 +68,7 @@ class SaleForm(forms.ModelForm):
return sale_price
class WriteOffForm(forms.ModelForm):
class Meta:
model = WriteOff
fields = ['batch', 'quantity', 'reason', 'document_number', 'notes']
widgets = {
'batch': forms.Select(attrs={'class': 'form-control'}),
'quantity': forms.NumberInput(attrs={'class': 'form-control', 'step': '0.001'}),
'reason': forms.Select(attrs={'class': 'form-control'}),
'document_number': forms.TextInput(attrs={'class': 'form-control'}),
'notes': forms.Textarea(attrs={'class': 'form-control', 'rows': 3}),
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Фильтруем партии - показываем только активные
self.fields['batch'].queryset = StockBatch.objects.filter(
is_active=True
).select_related('product', 'warehouse').order_by('-created_at')
def clean(self):
cleaned_data = super().clean()
batch = cleaned_data.get('batch')
quantity = cleaned_data.get('quantity')
if batch and quantity:
if quantity > batch.quantity:
raise ValidationError(
f'Невозможно списать {quantity} шт из партии, '
f'где только {batch.quantity} шт. '
f'Недостаток: {quantity - batch.quantity} шт.'
)
if quantity <= 0:
raise ValidationError('Количество должно быть больше нуля')
return cleaned_data
# WriteOffForm удалён - используйте WriteOffDocumentForm для работы с документами списания
class InventoryForm(forms.ModelForm):