save
This commit is contained in:
parent
286265ac59
commit
8e6e87a098
@ -33,7 +33,7 @@ from .models import (
|
|||||||
Staff,
|
Staff,
|
||||||
Opportunity, Priority, Sources, Lead, Activity, Notes, CarModel
|
Opportunity, Priority, Sources, Lead, Activity, Notes, CarModel
|
||||||
)
|
)
|
||||||
from django_ledger.models import ItemModel, InvoiceModel
|
from django_ledger.models import ItemModel, InvoiceModel,BillModel
|
||||||
from django.forms import ModelMultipleChoiceField, ValidationError, DateInput
|
from django.forms import ModelMultipleChoiceField, ValidationError, DateInput
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
import django_tables2 as tables
|
import django_tables2 as tables
|
||||||
@ -553,7 +553,10 @@ class ItemForm(forms.Form):
|
|||||||
|
|
||||||
class PaymentForm(forms.Form):
|
class PaymentForm(forms.Form):
|
||||||
invoice = forms.ModelChoiceField(
|
invoice = forms.ModelChoiceField(
|
||||||
queryset=InvoiceModel.objects.all(), label="Invoice", required=True
|
queryset=InvoiceModel.objects.all(), label="Invoice", required=False
|
||||||
|
)
|
||||||
|
bill = forms.ModelChoiceField(
|
||||||
|
queryset=BillModel.objects.all(), label="Bill", required=False
|
||||||
)
|
)
|
||||||
amount = forms.DecimalField(label="Amount", required=True)
|
amount = forms.DecimalField(label="Amount", required=True)
|
||||||
payment_method = forms.ChoiceField(
|
payment_method = forms.ChoiceField(
|
||||||
@ -571,15 +574,17 @@ class PaymentForm(forms.Form):
|
|||||||
|
|
||||||
def clean_amount(self):
|
def clean_amount(self):
|
||||||
invoice = self.cleaned_data['invoice']
|
invoice = self.cleaned_data['invoice']
|
||||||
|
bill = self.cleaned_data['bill']
|
||||||
|
model = invoice if invoice else bill
|
||||||
amount = self.cleaned_data['amount']
|
amount = self.cleaned_data['amount']
|
||||||
if amount < invoice.amount_due:
|
if amount + model.amount_paid > model.amount_due:
|
||||||
raise forms.ValidationError("Payment amount is greater than invoice amount due")
|
raise forms.ValidationError("Payment amount is greater than amount due")
|
||||||
if amount <= 0:
|
if amount <= 0:
|
||||||
raise forms.ValidationError("Payment amount must be greater than 0")
|
raise forms.ValidationError("Payment amount must be greater than 0")
|
||||||
if invoice.amount_due == invoice.amount_paid or invoice.invoice_status == "paid":
|
if model.is_paid():
|
||||||
raise forms.ValidationError("Invoice is already paid")
|
raise forms.ValidationError("Invoice is already paid")
|
||||||
if amount > invoice.amount_due:
|
if amount > model.amount_due:
|
||||||
raise forms.ValidationError("Payment amount is greater than invoice amount due")
|
raise forms.ValidationError("Payment amount is greater than amount due")
|
||||||
return amount
|
return amount
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user