Before simplifying order creation and editing
This commit is contained in:
@@ -263,13 +263,15 @@ class OrderItemForm(forms.ModelForm):
|
||||
self.fields['is_custom_price'].required = False
|
||||
|
||||
def clean_price(self):
|
||||
"""Парсим цену с запятой или точкой"""
|
||||
"""Парсим цену с запятой или точкой и округляем до 2 знаков"""
|
||||
value = self.cleaned_data.get('price')
|
||||
if value in (None, ''):
|
||||
return None
|
||||
value_str = str(value).strip().replace(',', '.')
|
||||
try:
|
||||
return Decimal(value_str)
|
||||
price = Decimal(value_str)
|
||||
# Округляем до 2 знаков после запятой
|
||||
return price.quantize(Decimal('0.01'))
|
||||
except Exception:
|
||||
raise forms.ValidationError('Введите число.')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user