-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from aabidsofi19/create-admin-dashbd
Create admin dashboard
- Loading branch information
Showing
242 changed files
with
13,908 additions
and
14,367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
apps/backend/Orders/migrations/0011_order_fulfillment_status.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.1.13 on 2022-02-06 17:10 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('Orders', '0010_auto_20220109_1000'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='order', | ||
name='fulfillment_status', | ||
field=models.CharField(choices=[('Unfulfilled', 'Unfulfilled'), ('PartiallyFulfilled', 'PartiallyFulfilled'), ('Fulfilled', 'Fulfilled')], default='Unfulfilled', max_length=50), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Generated by Django 3.1.13 on 2022-02-12 04:45 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('Users', '0008_auto_20220206_1710'), | ||
('Orders', '0011_order_fulfillment_status'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='orderitem', | ||
name='Address', | ||
), | ||
migrations.RemoveField( | ||
model_name='orderitem', | ||
name='fullfillment_status', | ||
), | ||
migrations.AddField( | ||
model_name='order', | ||
name='Address', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='Users.address'), | ||
), | ||
migrations.AddField( | ||
model_name='order', | ||
name='discount_percent', | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='order', | ||
name='tax_percent', | ||
field=models.IntegerField(default=0), | ||
), | ||
migrations.AddField( | ||
model_name='orderitem', | ||
name='fulfillment_status', | ||
field=models.CharField(choices=[('Unfulfilled', 'Unfulfilled'), ('PartiallyFulfilled', 'PartiallyFulfilled'), ('Fulfilled', 'Fulfilled')], default='Unfulfilled', max_length=50), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 3.1.13 on 2022-02-12 12:44 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('Orders', '0012_auto_20220212_0445'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='order', | ||
old_name='Customer', | ||
new_name='customer', | ||
), | ||
migrations.RenameField( | ||
model_name='order', | ||
old_name='extra_charges', | ||
new_name='shipping_charges', | ||
), | ||
migrations.RenameField( | ||
model_name='orderitem', | ||
old_name='Amount', | ||
new_name='amount', | ||
), | ||
migrations.RenameField( | ||
model_name='orderitem', | ||
old_name='Customer', | ||
new_name='customer', | ||
), | ||
migrations.RenameField( | ||
model_name='orderitem', | ||
old_name='Quantity', | ||
new_name='quantity', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 3.1.13 on 2022-02-19 06:48 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('Orders', '0013_auto_20220212_1244'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='order', | ||
old_name='Address', | ||
new_name='address', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Generated by Django 3.1.13 on 2022-02-19 07:05 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('Users', '0010_auto_20220219_0705'), | ||
('Orders', '0014_auto_20220219_0648'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='order', | ||
name='address', | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='Users.address'), | ||
), | ||
migrations.AlterField( | ||
model_name='order', | ||
name='customer', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Users.customer'), | ||
), | ||
migrations.AlterField( | ||
model_name='orderitem', | ||
name='customer', | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='Users.customer'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,119 @@ | ||
import operator | ||
from functools import reduce | ||
from django.db import models | ||
from Users.models import Customer,Address | ||
from shop.models import Product,Variation | ||
from Users.models import Customer, Address | ||
from cart.models import document_exists | ||
from shop.models import Product | ||
|
||
|
||
# Create your models here. | ||
class Order(models.Model): | ||
Customer=models.ForeignKey(Customer,on_delete=models.DO_NOTHING) | ||
paid=models.BooleanField(default=False) | ||
payment_methods=(('0','stripe_checkout'),('1','PaymentIntent')) | ||
Payment_Statuses =(("initiated","initiated"),("processing", "processing"),("succeeded","succeeded"), | ||
("failed","failed"),("cancelled","cancelled")) | ||
payment_method=models.CharField(choices=payment_methods,default='1',max_length=50) | ||
payment_id=models.CharField(max_length=100) | ||
payment_status= models.CharField(choices=Payment_Statuses,default='initiated',max_length=50) | ||
created_at=models.DateTimeField(auto_now_add=True) | ||
updated_at=models.DateTimeField(auto_now=True) | ||
extra_charges=models.IntegerField(default=0) | ||
|
||
customer = models.ForeignKey(Customer, on_delete=models.CASCADE) | ||
paid = models.BooleanField(default=False) | ||
payment_methods = (("0", "stripe_checkout"), ("1", "PaymentIntent")) | ||
|
||
Payment_Statuses = ( | ||
("initiated", "initiated"), | ||
("processing", "processing"), | ||
("succeeded", "succeeded"), | ||
("failed", "failed"), | ||
("cancelled", "cancelled"), | ||
) | ||
|
||
Fullfilment_Statuses = ( | ||
("Unfulfilled", "Unfulfilled"), | ||
("PartiallyFulfilled", "PartiallyFulfilled"), | ||
("Fulfilled", "Fulfilled"), | ||
) | ||
|
||
payment_method = models.CharField( | ||
choices=payment_methods, default="1", max_length=50 | ||
) | ||
|
||
payment_id = models.CharField(max_length=100) | ||
payment_status = models.CharField( | ||
choices=Payment_Statuses, default="initiated", max_length=50 | ||
) | ||
|
||
fulfillment_status = models.CharField( | ||
choices=Fullfilment_Statuses, default="Unfulfilled", max_length=50 | ||
) | ||
|
||
address = models.ForeignKey(Address, on_delete=models.PROTECT, null=True) | ||
tax_percent = models.IntegerField(default=0) | ||
discount_percent = models.IntegerField(default=0) | ||
shipping_charges = models.IntegerField(default=0) | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
updated_at = models.DateTimeField(auto_now=True) | ||
|
||
def __str__(self): | ||
return f"{self.Customer} {self.id}" | ||
return f"{self.customer} {self.id}" | ||
|
||
@property | ||
def total_amount(self): | ||
items=OrderItem.objects.filter(order=self) | ||
total_amount=self.extra_charges | ||
for item in items: | ||
total_amount+=item.total_amount() | ||
return total_amount | ||
items = OrderItem.objects.filter(order=self) | ||
subtotal = sum((x.total_amount for x in items)) | ||
subtotal = subtotal + self.shipping_charges | ||
subtotal = subtotal - (subtotal * self.discount_percent / 100) | ||
return subtotal + (subtotal * self.tax_percent / 100) | ||
|
||
@property | ||
def total_items(self): | ||
|
||
items = OrderItem.objects.filter(order=self) | ||
return len(items) | ||
|
||
@property | ||
def total_quantity(self): | ||
|
||
items = OrderItem.objects.filter(order=self) | ||
return reduce(sum, map(lambda x: x.quantity, items)) | ||
|
||
@property | ||
def total_weight(self): | ||
|
||
items = OrderItem.objects.filter(order=self) | ||
return reduce(sum, map(lambda x: x.product.weight * x.quantity, items)) | ||
|
||
@property | ||
def total_weight_in_grams(self): | ||
return self.total_weight() * 1000 | ||
|
||
|
||
# TODO : lowercase the quantity , weight , amount , customer in client | ||
class OrderItem(models.Model): | ||
order=models.ForeignKey(Order,on_delete=models.CASCADE) | ||
product_id= models.CharField(max_length=100,null=False) | ||
variation_id=models.CharField(null=False,max_length=50) | ||
Amount=models.IntegerField(null=False) #single item price | ||
Customer=models.ForeignKey(Customer,on_delete=models.DO_NOTHING) | ||
Address=models.ForeignKey(Address,on_delete=models.DO_NOTHING) | ||
Quantity=models.IntegerField(null=False) | ||
Order_date=models.DateTimeField(auto_now_add=True, blank=True ) | ||
|
||
details=models.TextField(max_length=500,null=True) | ||
paid=models.BooleanField(default=False) | ||
fullfillment_status=models.CharField(max_length=200,default='Unpaid') | ||
|
||
order = models.ForeignKey(Order, on_delete=models.CASCADE) | ||
product_id = models.CharField(max_length=100, null=False) | ||
variation_id = models.CharField(null=False, max_length=50) | ||
amount = models.IntegerField(null=False) # single item price | ||
customer = models.ForeignKey(Customer, on_delete=models.CASCADE) | ||
|
||
quantity = models.IntegerField(null=False) | ||
Order_date = models.DateTimeField(auto_now_add=True, blank=True) | ||
|
||
details = models.TextField(max_length=500, null=True) | ||
paid = models.BooleanField(default=False) | ||
|
||
Fullfilment_Statuses = ( | ||
("Unfulfilled", "Unfulfilled"), | ||
("PartiallyFulfilled", "PartiallyFulfilled"), | ||
("Fulfilled", "Fulfilled"), | ||
) | ||
fulfillment_status = models.CharField( | ||
choices=Fullfilment_Statuses, default="Unfulfilled", max_length=50 | ||
) | ||
|
||
@property | ||
def total_amount(self): | ||
return (self.Amount*self.Quantity) | ||
return self.amount * self.quantity | ||
|
||
@property | ||
def product(self): | ||
return Product.objects.get(id=self.product_id) | ||
|
||
|
||
if document_exists(lambda: Product.objects.get(id=self.product_id)): | ||
return Product.objects.get(id=self.product_id) | ||
else: | ||
return Product(name="does not exist") | ||
|
||
def __str__(self): | ||
return str(self.id) |
Oops, something went wrong.