Add qoute step.
This commit is contained in:
parent
b71ea45681
commit
6ff4740d04
30 changed files with 3362 additions and 376 deletions
|
@ -4,6 +4,9 @@ from common.models import NameSlugModel, BaseModel
|
|||
from simple_history.models import HistoricalRecords
|
||||
from django.core.exceptions import ValidationError
|
||||
from decimal import Decimal
|
||||
from django.utils import timezone
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.conf import settings
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
@ -123,6 +126,21 @@ class Quote(NameSlugModel):
|
|||
color = status_colors.get(self.status, 'secondary')
|
||||
return '<span class="badge bg-{}">{}</span>'.format(color, self.get_status_display())
|
||||
|
||||
def get_paid_amount(self):
|
||||
"""مبلغ پرداخت شده برای این پیشفاکتور بر اساس پرداختهای فاکتور مرتبط"""
|
||||
invoice = Invoice.objects.filter(quote=self).first()
|
||||
if not invoice:
|
||||
return Decimal('0')
|
||||
return sum(p.amount for p in invoice.payments.filter(is_deleted=False).all())
|
||||
|
||||
def get_remaining_amount(self):
|
||||
"""مبلغ باقیمانده بر اساس پرداختها"""
|
||||
paid = self.get_paid_amount()
|
||||
remaining = self.final_amount - paid
|
||||
if remaining < 0:
|
||||
remaining = Decimal('0')
|
||||
return remaining
|
||||
|
||||
class QuoteItem(BaseModel):
|
||||
"""مدل آیتمهای پیشفاکتور"""
|
||||
quote = models.ForeignKey(Quote, on_delete=models.CASCADE, related_name='items', verbose_name="پیشفاکتور")
|
||||
|
@ -311,6 +329,7 @@ class Payment(BaseModel):
|
|||
reference_number = models.CharField(max_length=100, verbose_name="شماره مرجع", blank=True)
|
||||
payment_date = models.DateField(verbose_name="تاریخ پرداخت")
|
||||
notes = models.TextField(verbose_name="یادداشتها", blank=True)
|
||||
receipt_image = models.ImageField(upload_to='payments/%Y/%m/%d/', null=True, blank=True, verbose_name="تصویر فیش")
|
||||
created_by = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name="ثبت کننده")
|
||||
history = HistoricalRecords()
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue