diff --git a/osinaweb/billing/models.py b/osinaweb/billing/models.py index ba6733f2..453e6e80 100644 --- a/osinaweb/billing/models.py +++ b/osinaweb/billing/models.py @@ -3,7 +3,6 @@ from osinacore.models import * import requests -# Create your models here. class Item(models.Model): TYPE = ( ('Product', 'Product'), @@ -17,6 +16,7 @@ class Item(models.Model): amount = models.FloatField(null=True) recurring = models.BooleanField(default=False) photo = models.ImageField(null=True, blank=True) + def __str__(self): return self.title @@ -25,6 +25,7 @@ class RecurringCycle(models.Model): item = models.ForeignKey(Item, on_delete=models.CASCADE, null=True) months = models.IntegerField() cycle_price = models.FloatField(null=True) + def __str__(self): if self.months > 1: return f"{self.months} months - {self.item}" @@ -37,16 +38,19 @@ class Order(models.Model): business = models.ForeignKey(Business, on_delete=models.SET_NULL, null=True, blank=True) order_id = models.CharField(max_length=100, null=True, blank=True) date = models.DateField(null=True, blank=True) + @property def get_cart_total(self): orderitems = self.orderitem_set.all() total = sum([item.get_total for item in orderitems]) - return total + return total + @property def get_paid_amount(self): payments = self.orderpayment_set.filter(date_paid__isnull=False) total_paid = sum([payment.amount for payment in payments]) return total_paid + @property def remaining_balance(self): return self.get_cart_total - self.get_paid_amount @@ -57,6 +61,7 @@ class Order(models.Model): if first_orderitem: return first_orderitem.purchased_at return None + def save(self, *args, **kwargs): if not self.order_id: current_year_last_two_digits = timezone.now().strftime('%y') @@ -71,7 +76,6 @@ class Order(models.Model): self.order_id = f'O{current_year_last_two_digits}{new_order_number_str}' super(Order, self).save(*args, **kwargs) - class OrderStatus(models.Model): STATUS = ( @@ -92,7 +96,7 @@ class OrderItem(models.Model): active = models.BooleanField(null=True, blank=True) purchased_at = models.DateField(null=True, blank=True) end_at = models.DateField(blank=True, null=True) - terminated_at = models.DateField(blank=True, null=True) + terminated_at = models.DateField(blank=True, null=True) recurring_cycle = models.ForeignKey(RecurringCycle, on_delete=models.SET_NULL, null=True, blank=True) @property def get_total(self): @@ -109,8 +113,10 @@ class Invoice(models.Model): order = models.OneToOneField(Order, on_delete=models.SET_NULL, null=True) date_created = models.DateField() pdf = models.FileField(upload_to='generated_invoices', null=True, blank=True) + def __str__(self): return self.invoice_number + @property def status(self): payments = OrderPayment.objects.filter(order=self.order) @@ -118,6 +124,7 @@ class Invoice(models.Model): return "Completed" else: return "Not Completed" + def save(self, *args, **kwargs): if not self.invoice_number: current_year = str(timezone.now().year)[-2:] @@ -135,6 +142,7 @@ class PaymentType(models.Model): name = models.CharField(max_length=100) description = models.TextField(null=True, blank=True) image = models.ImageField(null=True, blank=True) + def __str__(self): return self.name @@ -146,6 +154,7 @@ class OrderPayment(models.Model): date_due = models.DateField(null=True, blank=True) type = models.ManyToManyField(PaymentType, null=True) comment = models.TextField(null=True, blank=True) + def __str__(self): return f"Payment for {self.order}" @@ -154,5 +163,6 @@ class Receipt(models.Model): receipt_number = models.CharField(max_length=100) payment = models.ManyToManyField(OrderPayment) date_generated = models.DateField() + def __str__(self): - return self.receipt_number \ No newline at end of file + return self.receipt_number diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index 446cc2fa..74545bee 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/templates/details_templates/customer-details.html b/osinaweb/osinacore/templates/details_templates/customer-details.html index 8c0b0551..64c42e62 100644 --- a/osinaweb/osinacore/templates/details_templates/customer-details.html +++ b/osinaweb/osinacore/templates/details_templates/customer-details.html @@ -327,6 +327,70 @@ {% endif %} + + {% if customer_orders %} +
+
+
+

Payments

+
+ + +
+ +
+ + + + + + + + + +{# #} + + + + + {% for order in customer_orders %} + + + + + + + + + + {% endfor %} +
+ Order ID + + Business + + Date + + Total + #} +{# Actions#} +{#
+

{{order.order_id}}

+
+

${{order.business.name}}

+
+

{{order.date}}

+
+
+
+ {% endif %} {% if customer_payments %} diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index e1bca595..a579092f 100644 --- a/osinaweb/osinacore/views.py +++ b/osinaweb/osinacore/views.py @@ -488,12 +488,14 @@ def customerdetails(request, customer_id): customer_projects = Project.objects.filter(customer=customer).order_by('-id') customer_payments = OrderPayment.objects.filter(order__customer=customer).order_by('-id') customer_active_subscriptions = OrderItem.objects.filter(active=True, order__customer=customer) + customer_orders = Order.objects.filter(customer=customer) context = { - 'customer' : customer, - 'customer_projects' : customer_projects, + 'customer': customer, + 'customer_projects': customer_projects, 'customer_payments': customer_payments, 'customer_active_subscriptions': customer_active_subscriptions, + 'customer_orders': customer_orders, } return render(request, 'details_templates/customer-details.html', context)