-
Notifications
You must be signed in to change notification settings - Fork 45
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
1 parent
79dfa27
commit 9140b40
Showing
12 changed files
with
333 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.8 on 2016-08-10 17:02 | ||
from __future__ import unicode_literals | ||
|
||
import annoying.fields | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('order', '0006_auto_20160803_2217'), | ||
('member', '0011_client_delivery_note'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Billing', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('total_amount', models.DecimalField(decimal_places=2, max_digits=6, verbose_name='total_amount')), | ||
('billing_month', models.IntegerField()), | ||
('billing_year', models.IntegerField()), | ||
('generation_date', models.DateTimeField(auto_now=True)), | ||
('detail', annoying.fields.JSONField()), | ||
('client', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='member.Client')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='OrderBilling', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('billing_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='client_billing', to='billing.Billing')), | ||
('order_id', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='client_order', to='order.Order')), | ||
], | ||
), | ||
] |
27 changes: 27 additions & 0 deletions
27
django/santropolFeast/billing/migrations/0002_billingcycle.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,27 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.8 on 2016-08-10 18:31 | ||
from __future__ import unicode_literals | ||
|
||
import annoying.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('billing', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='BillingCycle', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('total_order', models.IntegerField()), | ||
('detail', annoying.fields.JSONField()), | ||
('billing_year', models.IntegerField()), | ||
('billing_month', models.IntegerField()), | ||
('amount_total', models.DecimalField(decimal_places=2, max_digits=6)), | ||
], | ||
), | ||
] |
19 changes: 19 additions & 0 deletions
19
django/santropolFeast/billing/migrations/0003_auto_20160810_1957.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,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.8 on 2016-08-10 19:57 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('billing', '0002_billingcycle'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameModel( | ||
old_name='BillingCycle', | ||
new_name='BillingSummary', | ||
), | ||
] |
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,3 +1,77 @@ | ||
from django.db import models | ||
from member.models import Client | ||
from order.models import Order | ||
from annoying.fields import JSONField | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
# Create your models here. | ||
|
||
class OrderBilling(models.Model): | ||
order_id = models.ForeignKey( | ||
"order.Order", | ||
related_name='client_order' | ||
) | ||
billing_id = models.ForeignKey( | ||
"billing.Billing", | ||
related_name='client_billing' | ||
) | ||
|
||
|
||
class BillingManager(models.Manager): | ||
|
||
def get_all_billing_client(self, client): | ||
pass | ||
|
||
|
||
class Billing(models.Model): | ||
client = models.ForeignKey( | ||
"member.Client", | ||
) | ||
|
||
total_amount = models.DecimalField( | ||
verbose_name=_('total_amount'), | ||
max_digits=6, | ||
decimal_places=2 | ||
) | ||
|
||
# Month start with january is 1 | ||
billing_month = models.IntegerField() | ||
|
||
billing_year = models.IntegerField() | ||
|
||
generation_date = models.DateTimeField( | ||
verbose_name=None, auto_now=True | ||
) | ||
|
||
detail = JSONField() | ||
|
||
|
||
class BillingSummary(models.Model): | ||
|
||
total_order = models.IntegerField() | ||
detail = JSONField() | ||
billing_year = models.IntegerField() | ||
billing_month = models.IntegerField() | ||
amount_total = models.DecimalField( | ||
max_digits=6, | ||
decimal_places=2, | ||
) | ||
|
||
|
||
# get the total amount from a list of orders | ||
def calculate_amount_total(orders): | ||
|
||
total = 0 | ||
|
||
for order in orders: | ||
|
||
total += order.price | ||
|
||
return total | ||
|
||
|
||
# get the order detail from a list of orders | ||
def get_order_detail(self, orders): | ||
|
||
detail = {"meal_regular": 0, "meal_large": 0} |
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,2 @@ | ||
{% extends "base.html" %} | ||
{% load i18n %} |
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 @@ | ||
{% extends "base_billing" %} | ||
{% load i18n %} | ||
{% load static %} | ||
|
||
{% block title %}{% trans'Billing' %}{% endblock %} |
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 @@ | ||
{% extends "base_billing" %} | ||
{% load i18n %} | ||
{% load static %} | ||
|
||
{% block title %}{% trans'Billing' %}{% endblock %} |
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,8 @@ | ||
{% extends "base_billing" %} | ||
{% load i18n %} | ||
{% load static %} | ||
|
||
{% block title %}{% trans'Billing' %}{% endblock %} | ||
{% block content %} | ||
|
||
{% endblock %} |
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,3 +1,42 @@ | ||
from django.test import TestCase | ||
from order.factories import OrderFactory, OrderItemFactory | ||
from billing.models import Billing, calculate_amount_total | ||
import datetime | ||
from member.factories import ClientFactory, RouteFactory | ||
from order.models import Order | ||
|
||
# Create your tests here. | ||
|
||
class TestBilling(TestCase): | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
RouteFactory.create_batch(10) | ||
|
||
def testTotalAmount(self): | ||
order = OrderFactory(delivery_date=datetime.datetime.today()) | ||
orders = [] | ||
orders.append(order) | ||
|
||
total_amount = calculate_amount_total(orders) | ||
|
||
self.assertEqual(total_amount, order.price) | ||
|
||
def testOrderDetail(self): | ||
pass | ||
|
||
def testGetOrderForMonth(self): | ||
|
||
order = OrderFactory( | ||
delivery_date=datetime.datetime.today(), status="D" | ||
) | ||
month = datetime.datetime.now().strftime("%m") | ||
print(month) | ||
year = datetime.datetime.now().strftime("%y") | ||
print(year) | ||
orders = Order.objects.get_orders_for_month(month, year) | ||
|
||
self.assertEqual(order, orders.first()) | ||
|
||
|
||
def testGetOrderForMonthClient(self): | ||
pass |
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,10 @@ | ||
from django.conf.urls import url | ||
from billing.views import BillingList, BillingCreate, delete_billing | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
urlpatterns = [ | ||
url(r'^list/', BillingList.as_view(), name="list"), | ||
url(r'^create', BillingCreate.as_view(), name="create"), | ||
url(r'^view/(?<pk>\d+)/$', BillingView.as_view(), name="view"), | ||
url(r'^delete/(?<pk>\d+)/$', BillingDelete.as_view(), name='delete'), | ||
] |
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,3 +1,88 @@ | ||
from django.shortcuts import render | ||
from django.views import generic | ||
from billing.models import Billing, OrderBilling, calculate_amount_total | ||
from django.shortcuts import login_required | ||
from order.models import get_orders_for_month_client | ||
|
||
# Create your views here. | ||
|
||
class BillingList(generic.ListView): | ||
# Display the billing list | ||
model = Billing | ||
template_name = "list.html" | ||
context_object_name = "billing" | ||
|
||
@method_decorator(login_required) | ||
def dispatch(self, *args, **kwargs): | ||
return super(BillingList, self).dispatch(*args, **kwargs) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super(BillingList, self).get_context_data(**kwargs) | ||
|
||
# Context variable | ||
context['myVariableOfContext'] = 0 | ||
|
||
return context | ||
|
||
|
||
class BillingCreate(generic.CreateView): | ||
# View to create the billing | ||
|
||
model = Billing | ||
template_name = "create.html" | ||
context_object_name = "billing" | ||
|
||
@method_decorator(login_required) | ||
def dispatch(self, *args, **kwargs): | ||
return super(BillingCreate, self).dispatch(*args, **kwargs) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super(BillingCreate, self).get_context_data(**kwargs) | ||
|
||
# Context variable | ||
context['myVariableOfContext'] = 0 | ||
|
||
return context | ||
|
||
def create_bill(client, year, month): | ||
|
||
orders = get_orders_for_month_client(month, year, client) | ||
|
||
billing = Billing.objects.create( | ||
client=client, | ||
total_amount=calculate_amount_total(orders), | ||
billing_month=month, | ||
billing_year=year, | ||
generation_date=datetime.now(), | ||
detail=get_order_detail(orders), | ||
) | ||
|
||
for order in orders: | ||
OrderBilling.objects.create( | ||
order_id=order.id, | ||
billing_id=billing.id | ||
) | ||
|
||
return billing | ||
|
||
|
||
class BillingView(generic.DetailView): | ||
# Display detail of billing | ||
model = Billing | ||
template_name = "view.html" | ||
context_object_name = "billing" | ||
|
||
@method_decorator(login_required) | ||
def dispatch(self, *args, **kwargs): | ||
return super(BillingView, self).dispatch(*args, **kwargs) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super(BillingView, self).get_context_data(**kwargs) | ||
|
||
# Context variable | ||
context['myVariableOfContext'] = 0 | ||
|
||
return context | ||
|
||
|
||
class BillingDelete(generic.DeleteView): | ||
pass |
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