-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Working on getting get_scope and get_aggregate to function'
- Loading branch information
Showing
25 changed files
with
381 additions
and
347 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,15 @@ | ||
from django.contrib import admin | ||
from .models import Purchase | ||
|
||
class WidgetInLine(admin.TabularInline): | ||
model = Purchase.items.through | ||
|
||
|
||
class PurchaseAdmin(admin.ModelAdmin): | ||
model = Purchase | ||
list_display = ('sale_date', 'sale_price', 'profit') | ||
list_filter = ('sale_date', 'sale_price', 'profit') | ||
inlines = [WidgetInLine] | ||
|
||
|
||
admin.site.register(Purchase, PurchaseAdmin) |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class PurchasesConfig(AppConfig): | ||
name = 'purchases' |
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,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.6 on 2018-07-11 17:33 | ||
from __future__ import unicode_literals | ||
|
||
import DjangoEasyScoping.ScopingMixin | ||
import datetime | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('widgets', '0005_auto_20180711_1733'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Purchase', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('sale_date', models.DateTimeField(default=datetime.datetime.now)), | ||
('sale_price', models.DecimalField(blank=True, decimal_places=2, default=0, max_digits=10)), | ||
('profit', models.DecimalField(blank=True, decimal_places=2, default=0, max_digits=10)), | ||
('items', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='widgets.Widget')), | ||
], | ||
bases=(DjangoEasyScoping.ScopingMixin.ScopingMixin, models.Model), | ||
), | ||
] |
25 changes: 25 additions & 0 deletions
25
easy_scoping/purchases/migrations/0002_auto_20180711_1741.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,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.10.6 on 2018-07-11 17:41 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('widgets', '0005_auto_20180711_1733'), | ||
('purchases', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='purchase', | ||
name='items', | ||
), | ||
migrations.AddField( | ||
model_name='purchase', | ||
name='items', | ||
field=models.ManyToManyField(to='widgets.Widget'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
easy_scoping/purchases/migrations/0003_auto_20180711_2003.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 2.0.6 on 2018-07-11 20:03 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('purchases', '0002_auto_20180711_1741'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='purchase', | ||
name='items', | ||
field=models.ManyToManyField(blank=True, to='widgets.Widget'), | ||
), | ||
] |
23 changes: 23 additions & 0 deletions
23
easy_scoping/purchases/migrations/0004_auto_20180711_2237.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,23 @@ | ||
# Generated by Django 2.0.6 on 2018-07-11 22:37 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('purchases', '0003_auto_20180711_2003'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='purchase', | ||
name='profit', | ||
field=models.FloatField(blank=True, default=0), | ||
), | ||
migrations.AlterField( | ||
model_name='purchase', | ||
name='sale_price', | ||
field=models.FloatField(blank=True, default=0), | ||
), | ||
] |
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,52 @@ | ||
import django | ||
from django.db import models | ||
from widgets.models import Widget | ||
from DjangoEasyScoping.ScopingMixin import ScopingMixin, ScopingQuerySet | ||
|
||
|
||
class Purchase(ScopingMixin, models.Model): | ||
items = models.ManyToManyField(Widget, blank=True) | ||
sale_date = models.DateTimeField(default=django.utils.timezone.now) | ||
sale_price = models.FloatField(default=0, | ||
blank=True) | ||
profit = models.FloatField(default=0, | ||
blank=True) | ||
|
||
objects = ScopingQuerySet.as_manager() | ||
|
||
def get_items(self): | ||
return self.items.all() | ||
|
||
def get_item_count(self): | ||
return self.items.all().count() | ||
|
||
def get_sale_date(self): | ||
return self.sale_date | ||
|
||
def get_sale_price(self): | ||
return self.sale_price | ||
|
||
def get_cost(self): | ||
from django.db.models import Sum | ||
return round(self.items.aggregate(cost=Sum('cost'))['cost'], 2) | ||
|
||
def get_profit(self): | ||
return self.profit | ||
|
||
def set_sale_price(self): | ||
cost_plus_profit= 1.1 | ||
cost = self.get_cost() | ||
self.sale_price = round(cost*cost_plus_profit, 2) | ||
|
||
def set_profit(self): | ||
profit_margin = .1 | ||
cost = self.get_cost() | ||
self.profit = round(cost*profit_margin, 2) | ||
|
||
def save(self, *args, **kwargs): | ||
if self.id: | ||
for item in Widget.objects.filter(purchase=self): | ||
self.items.add(item) | ||
self.set_sale_price() | ||
self.set_profit() | ||
super(Purchase, self).save(*args, **kwargs) |
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.shortcuts import render | ||
|
||
# Create your views 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,23 @@ | ||
import datetime as dt | ||
import pytz | ||
import random | ||
import factory | ||
import factory.fuzzy as fuz | ||
from purchases.models import Purchase | ||
from widgets.models import Widget | ||
|
||
|
||
class PurchaseFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = Purchase | ||
|
||
sale_date = fuz.FuzzyDateTime(dt.datetime(1950, 1, 1, tzinfo=pytz.UTC)) | ||
|
||
@factory.post_generation | ||
def items(self, create, purchased, **kwargs): | ||
amt_purchased = random.randint(1, 10) | ||
purchased = Widget.objects.all().order_by('?')[:amt_purchased] | ||
|
||
if create and purchased: | ||
for item in purchased: | ||
self.items.add(item) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.