-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
1,454 additions
and
227 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
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
Empty file.
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,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class DemoAppConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "demo_app" |
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,45 @@ | ||
from django import forms | ||
from django.db.models import Q | ||
from slick_reporting.forms import BaseReportForm | ||
|
||
|
||
class TotalSalesFilterForm(BaseReportForm, forms.Form): | ||
PRODUCT_SIZE_CHOICES = ( | ||
("all", "All"), | ||
("big-only", "Big Only"), | ||
("small-only", "Small Only"), | ||
("medium-only", "Medium Only"), | ||
("all-except-extra-big", "All except extra Big"), | ||
) | ||
start_date = forms.DateField( | ||
required=False, | ||
label="Start Date", | ||
widget=forms.DateInput(attrs={"type": "date"}), | ||
) | ||
end_date = forms.DateField( | ||
required=False, label="End Date", widget=forms.DateInput(attrs={"type": "date"}) | ||
) | ||
product_size = forms.ChoiceField( | ||
choices=PRODUCT_SIZE_CHOICES, required=False, label="Product Size", initial="all" | ||
) | ||
|
||
def get_filters(self): | ||
# return the filters to be used in the report | ||
# Note: the use of Q filters and kwargs filters | ||
kw_filters = {} | ||
q_filters = [] | ||
if self.cleaned_data["product_size"] == "big-only": | ||
kw_filters["product__size__in"] = ["extra_big", "big"] | ||
elif self.cleaned_data["product_size"] == "small-only": | ||
kw_filters["product__size__in"] = ["extra_small", "small"] | ||
elif self.cleaned_data["product_size"] == "medium-only": | ||
kw_filters["product__size__in"] = ["medium"] | ||
elif self.cleaned_data["product_size"] == "all-except-extra-big": | ||
q_filters.append(~Q(product__size__in=["extra_big", "big"])) | ||
return q_filters, kw_filters | ||
|
||
def get_start_date(self): | ||
return self.cleaned_data["start_date"] | ||
|
||
def get_end_date(self): | ||
return self.cleaned_data["end_date"] |
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,90 @@ | ||
import datetime | ||
import random | ||
from datetime import timedelta | ||
|
||
from django.contrib.auth import get_user_model | ||
from django.core.management.base import BaseCommand | ||
|
||
# from expense.models import Expense, ExpenseTransaction | ||
from ...models import Client, Product, SalesTransaction, ProductCategory | ||
|
||
User = get_user_model() | ||
|
||
|
||
def date_range(start_date, end_date): | ||
for i in range((end_date - start_date).days + 1): | ||
yield start_date + timedelta(i) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Create Sample entries for the demo app" | ||
|
||
def handle(self, *args, **options): | ||
# create clients | ||
models_list = [ | ||
Client, | ||
Product, | ||
] | ||
client_countries = [ | ||
"US", | ||
"DE", | ||
"EG", | ||
"IN", | ||
"KW", | ||
"RA" | ||
] | ||
product_category = [ | ||
"extra_big", | ||
"big", | ||
"medium", | ||
"small", | ||
"extra-small" | ||
] | ||
SalesTransaction.objects.all().delete() | ||
Client.objects.all().delete() | ||
Product.objects.all().delete() | ||
ProductCategory.objects.all().delete() | ||
User.objects.filter(is_superuser=False).delete() | ||
for i in range(10): | ||
User.objects.create_user(username=f"user {i}", password="password") | ||
|
||
users_id = list(User.objects.values_list("id", flat=True)) | ||
for i in range(1, 4): | ||
ProductCategory.objects.create(name=f"Product Category {i}") | ||
|
||
product_category_ids = list(ProductCategory.objects.values_list("id", flat=True)) | ||
for i in range(1, 10): | ||
Client.objects.create(name=f"Client {i}", | ||
country=random.choice(client_countries), | ||
# owner_id=random.choice(users_id) | ||
) | ||
clients_ids = list(Client.objects.values_list("pk", flat=True)) | ||
# create products | ||
for i in range(1, 10): | ||
Product.objects.create(name=f"Product {i}", | ||
product_category_id=random.choice(product_category_ids), | ||
size=random.choice(product_category)) | ||
products_ids = list(Product.objects.values_list("pk", flat=True)) | ||
|
||
current_year = datetime.datetime.today().year | ||
start_date = datetime.datetime(current_year, 1, 1) | ||
end_date = datetime.datetime(current_year + 1, 1, 1) | ||
|
||
for date in date_range(start_date, end_date): | ||
for i in range(1, 10): | ||
SalesTransaction.objects.create( | ||
client_id=random.choice(clients_ids), | ||
product_id=random.choice(products_ids), | ||
quantity=random.randint(1, 10), | ||
price=random.randint(1, 100), | ||
date=date, | ||
number=f"Sale {date.strftime('%Y-%m-%d')} #{i}", | ||
) | ||
# ExpenseTransaction.objects.create( | ||
# expense_id=random.choice(expense_ids), | ||
# value=random.randint(1, 100), | ||
# date=date, | ||
# number=f"Expense {date.strftime('%Y-%m-%d')} #{i}", | ||
# ) | ||
|
||
self.stdout.write(self.style.SUCCESS("Entries Created Successfully")) |
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,94 @@ | ||
# Generated by Django 4.2 on 2023-08-02 09:14 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Client", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=100, verbose_name="Client Name")), | ||
], | ||
options={ | ||
"verbose_name": "Client", | ||
"verbose_name_plural": "Clients", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Product", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=100, verbose_name="Product Name")), | ||
], | ||
options={ | ||
"verbose_name": "Product", | ||
"verbose_name_plural": "Products", | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="SalesTransaction", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"number", | ||
models.CharField( | ||
max_length=100, verbose_name="Sales Transaction #" | ||
), | ||
), | ||
("date", models.DateTimeField()), | ||
("notes", models.TextField(blank=True, null=True)), | ||
("value", models.DecimalField(decimal_places=2, max_digits=9)), | ||
( | ||
"client", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="demo_app.client", | ||
verbose_name="Client", | ||
), | ||
), | ||
( | ||
"product", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
to="demo_app.product", | ||
verbose_name="Product", | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Sales Transaction", | ||
"verbose_name_plural": "Sales Transactions", | ||
}, | ||
), | ||
] |
Oops, something went wrong.