Skip to content

Commit

Permalink
Merge pull request #3 from aabidsofi19/create-admin-dashbd
Browse files Browse the repository at this point in the history
Create admin dashboard
  • Loading branch information
aabidsofi19 authored Mar 5, 2022
2 parents e03d2c6 + 37ebd17 commit f3b612c
Show file tree
Hide file tree
Showing 242 changed files with 13,908 additions and 14,367 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Turborepo starter

This is an official Yarn v1 starter turborepo.
This is an official Mono repo for the Zivero Ecommerce Engine

## What's inside?

This turborepo uses [Yarn](https://classic.yarnpkg.com/lang/en/) as a package manager. It includes the following packages/apps:

### Apps and Packages

- `docs`: a [Next.js](https://nextjs.org) app
- `backend`: a Django app
- `web`: another [Next.js](https://nextjs.org) app
- `ui`: a stub React component library shared by both `web` and `docs` applications
- `config`: `eslint` configurations (includes `eslint-config-next` and `eslint-config-prettier`)
Expand Down
18 changes: 18 additions & 0 deletions apps/backend/Orders/migrations/0011_order_fulfillment_status.py
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),
),
]
43 changes: 43 additions & 0 deletions apps/backend/Orders/migrations/0012_auto_20220212_0445.py
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),
),
]
38 changes: 38 additions & 0 deletions apps/backend/Orders/migrations/0013_auto_20220212_1244.py
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',
),
]
18 changes: 18 additions & 0 deletions apps/backend/Orders/migrations/0014_auto_20220219_0648.py
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',
),
]
30 changes: 30 additions & 0 deletions apps/backend/Orders/migrations/0015_auto_20220219_0705.py
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'),
),
]
139 changes: 102 additions & 37 deletions apps/backend/Orders/models.py
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)
Loading

0 comments on commit f3b612c

Please sign in to comment.