This commit is contained in:
Marwan Alwali 2024-12-24 17:13:00 +03:00
parent 167b6862e9
commit ff85feccdf
2 changed files with 29 additions and 2 deletions

View File

@ -648,6 +648,9 @@ class SaleQuotation(models.Model):
("DRAFT", _("Draft")),
("CONFIRMED", _("Confirmed")),
("CANCELED", _("Canceled")),
("EXPIRED", _("Expired")),
("PARTIALLY", _("Partially")),
("COMPLETED", _("Completed")),
]
dealer = models.ForeignKey(
Dealer, on_delete=models.CASCADE, related_name="sales", null=True
@ -827,7 +830,7 @@ class Payment(models.Model):
verbose_name_plural = _("payments")
def __str__(self):
return f"Payment of {self.amount} on {self.date} for {self.order}"
return f"Payment of {self.amount} on {self.payment_date} for {self.quotation}"
class Refund(models.Model):

View File

@ -1,7 +1,8 @@
from random import randint
from django.db.models.signals import post_save, post_delete,pre_delete
from django.db.models.signals import post_save, post_delete, pre_delete, pre_save
from django.dispatch import receiver
from django.utils import timezone
from django_ledger.models import EntityModel
from django.utils.translation import gettext_lazy as _
@ -251,3 +252,26 @@ def create_customer(sender, instance, created, **kwargs):
# default_amount=instance.cost_price,
# )
# print(f"Inventory item updated with CarFinance data for Car: {instance.car}")
@receiver(pre_save, sender=models.SaleQuotation)
def update_quotation_status(sender, instance, **kwargs):
if instance.valid_until and timezone.now() > instance.valid_until:
instance.status = 'expired'
# instance.total_price = instance.calculate_total_price()
@receiver(post_save, sender=models.Payment)
def update_status_on_payment(sender, instance, created, **kwargs):
if created:
quotation = instance.sale_quotation
total_payments = sum(payment.amount for payment in quotation.payments.all())
if total_payments >= quotation.amount:
quotation.status = 'completed'
# SalesInvoice.objects.create(sales_order=order)
elif total_payments > 0:
quotation.status = 'partially_paid'
else:
quotation.status = 'pending'
quotation.save()