Skip to content

Commit

Permalink
Merge branch 'revenue_and_stat'
Browse files Browse the repository at this point in the history
  • Loading branch information
ioO committed Jun 26, 2018
2 parents 4d999d1 + 0509a75 commit e7e9011
Show file tree
Hide file tree
Showing 10 changed files with 474 additions and 9 deletions.
26 changes: 22 additions & 4 deletions billjobs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django import forms
from django.http import HttpResponse
from django.db.models import Q
from django.conf.urls import url
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
Expand All @@ -11,6 +12,22 @@
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _
from .models import Bill, BillLine, Service, UserProfile
from .views import statistics


class BilljobsAdminSite(admin.AdminSite):
index_template = 'billjobs/admin_index.html'

def get_urls(self):
urls = super(BilljobsAdminSite, self).get_urls()

my_urls = [
url(r'^statistics$', self.admin_view(statistics),
name='billjobs_statistics')
]

return my_urls + urls


class BillLineInlineForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
Expand Down Expand Up @@ -135,9 +152,10 @@ class ServiceAdmin(admin.ModelAdmin):
list_editable = ('is_available',)
list_filter = ('is_available',)

admin.site.register(Bill, BillAdmin)
admin.site.register(Service, ServiceAdmin)

admin_site = BilljobsAdminSite(name='myadmin')
# User have to be unregistered
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
# admin_site.unregister(User)
admin_site.register(User, UserAdmin)
admin_site.register(Bill, BillAdmin)
admin_site.register(Service, ServiceAdmin)
9 changes: 9 additions & 0 deletions billjobs/templates/billjobs/admin_index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{% extends "admin/index.html" %}
{% load i18n %}

{% block content %}
<div class="module">
<a href="/admin/statistics">Statistiques</a>
</div>
{{ block.super }}
{% endblock %}
170 changes: 170 additions & 0 deletions billjobs/templates/billjobs/statistics.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
{% extends "billjobs/base.html" %}
{% block body %}
<section class="section">
<div class="container">
<a href="{% url 'admin:index' %}">Accueil</a>
<h2 class="title is-3">Statistiques</h2>
</div>
</section>

<section class="section">
<div class="container">
<div class="columns">


<div class="column">
<p class="title is-4">Chiffre d'affaire {{ current_month_name | title}} {{ current_year }}</p>
<p class="subtitle is-4" style="background-color: hsla(204, 86%, 53%, 0.25); line-height: 200px; height: 200px; width: 200px; border-radius: 100%; text-align: center; border: 3px dotted black">{{ current_month_revenue}} €</p>
</div>
<div class="column">
<p class="title is-4">Chiffre d'affaire {{ previous_month_name | title}} {{ current_year }}</p>
<p class="subtitle is-4" style="background-color: hsla(204, 86%, 53%, 0.5); line-height: 200px; height: 200px; width: 200px; border-radius: 100%; text-align: center; border: 3px solid black">{{ previous_month_revenue}} €</p>
</div>
</div>
</div>
</section>
<section class="section">
<div class="container">
<table class="table is-striped is-fullwidth">
<tr>
<th class="is-info">Chiffre d'affaire {{ current_month_name }} {{ current_year }}</th>
<th class="is-info">Chiffre d'affaire {{ previous_month_name }} {{ current_year }}</th>
</tr>
<tr>
<td>{{ current_month_revenue}} €</td>
<td>{{ previous_month_revenue}} €</td>
</tr>
</table>
</div>
</section>

<section class="section">
<div class="container">

<table class="table is-striped is-fullwidth">
<p class="title is-4">Chiffre d'affaire annuel</p>

<tr>
<th class="is-info">Année</th>
{% for month in get_month %}
<th class="is-info">{{ month | title}}</th>
{% endfor %}
<th class="is-danger">Total</th>
</tr>
<tr>
<td>{{ current_year}}</td>
{% for revenue in current_monthly_revenue %}
<td>{{revenue}}</td>
{% endfor %}
<td>{{ current_year_revenue }}<span class="icon has-text-info"
style="border: 1px solid hsl(204, 86%, 53%); border-radius: 100%; cursor: pointer"
title="Estimation du CA annuel : somme des mois finis divisée
par le nombre de mois multipliés par 12.">
i
</span></td>
</tr>
<tr>
<td>{{ previous_year }}</td>
{% for revenue in previous_monthly_revenue %}
<td>{{revenue}}</td>
{% endfor %}
<td>{{ previous_year_revenue }}</td>
</tr>

</table>
</div>
</section>

<section class="section">
<div class="container">

</table>


<table class="table is-striped is-fullwidth">
<p class="title is-4">Abonnements / Services {{ current_year }}</p>

<tr>
<th class="is-info"></th>
{% for month in get_month %}
<th class="is-info">{{ month | title}}</th>
{% endfor %}
<th class="is-danger">Total</th>
</tr>
<tr>
<td>Full Time</td>
{% for subscriptions in current_monthly_subscriptions_1 %}
<td>{{subscriptions}}</td>
{% endfor %}
<td>{{ current_year_subscriptions_1 }}</td>
</tr>
<tr>
<td>Mid Time</td>
{% for subscriptions in current_monthly_subscriptions_2 %}
<td>{{subscriptions}}</td>
{% endfor %}
<td>{{ current_year_subscriptions_2 }}</td>
</tr>

<tr>
<td>Meeting 1 day</td>
{% for subscriptions in current_monthly_subscriptions_3 %}
<td>{{subscriptions}}</td>
{% endfor %}
<td>{{ current_year_subscriptions_3 }}</td>
</tr>


</table>



</div>
</section>


<section class="section">
<div class="container">

</table>
<table class="table is-striped is-fullwidth">
<p class="title is-4">Abonnements / Services {{ previous_year}}</p>

<tr>
<th class="is-info"></th>
{% for month in get_month %}
<th class="is-info">{{ month | title}}</th>
{% endfor %}
<th class="is-danger">Total</th>
</tr>
<tr>
<td>Full Time</td>
{% for subscriptions in previous_monthly_subscriptions_1 %}
<td>{{subscriptions}}</td>
{% endfor %}
<td>{{ previous_year_subscriptions_1 }}</td>
</tr>
<tr>
<td>Mid Time</td>
{% for subscriptions in previous_monthly_subscriptions_2 %}
<td>{{subscriptions}}</td>
{% endfor %}
<td>{{ previous_year_subscriptions_2 }}</td>
</tr>

<tr>
<td>Meeting 1 day</td>
{% for subscriptions in previous_monthly_subscriptions_3 %}
<td>{{subscriptions}}</td>
{% endfor %}
<td>{{ previous_year_subscriptions_3 }}</td>
</tr>

</table>



</div>
</section>

{% endblock body %}
56 changes: 56 additions & 0 deletions billjobs/tests/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import factory
import factory.fuzzy
import factory.django
from django.contrib.auth.models import User
from django.db.models.signals import post_save


@factory.django.mute_signals(post_save)
class UserProfileFactory(factory.django.DjangoModelFactory):
class Meta:
model = 'billjobs.UserProfile'

billing_address = factory.Faker('address')
user = factory.SubFactory(
'billjobs.tests.factories.UserFactory', profile=None)


@factory.django.mute_signals(post_save)
class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
django_get_or_create = ('username',)

username = 'steve'
password = 'gates'
first_name = 'Steve'
last_name = 'Gates'
email = 'steve.gates@billjobs.org'
userprofile = factory.RelatedFactory(UserProfileFactory, 'user')


class SuperUserFactory(UserFactory):
username = 'bill'
password = 'jobs'
first_name = 'Bill'
last_name = 'Jobs'
email = 'bill.jobs@billjobs.org'
is_staff = True
is_superuser = True


class ServiceFactory(factory.django.DjangoModelFactory):
class Meta:
model = 'billjobs.Service'

reference = factory.Sequence(lambda n: 'SE%03d' % n)
price = factory.fuzzy.FuzzyInteger(100, 200, 10)


class BillFactory(factory.django.DjangoModelFactory):
class Meta:
model = 'billjobs.Bill'
django_get_or_create = ('user',)

user = factory.SubFactory(UserFactory)
amount = factory.fuzzy.FuzzyInteger(100, 200, 10)
27 changes: 27 additions & 0 deletions billjobs/tests/tests_statistics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.test import TestCase
from django.shortcuts import reverse
from billjobs.tests.factories import UserFactory, SuperUserFactory, BillFactory


class Statistics(TestCase):
'''Tests statistics display page'''

def setUp(self):
self.admin = SuperUserFactory()
self.user = UserFactory()
self.bill = BillFactory.create(user=self.user)
self.bill.billing_date = '2018-01-01'
self.bill.save()

def test_login_required(self):
'''Test redirect to admin login page'''
response = self.client.get('/admin/statistics', follow=True)
self.assertRedirects(
response, '/admin/login/?next=/admin/statistics')

def test_admin_access_stats(self):
'''Test an authenticated admin can view statistic page'''
self.client.force_login(self.admin)
response = self.client.get(
'/admin/statistics', follow=False)
self.assertEqual(response.status_code, 200)
5 changes: 4 additions & 1 deletion billjobs/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from django.conf.urls import url
from . import views


from .admin import admin_site

urlpatterns = [
url(r'^generate_pdf/(?P<bill_id>\d+)$', views.generate_pdf,
name='generate-pdf'),
url(r'^signup/$', views.signup, name='billjobs_signup'),
url(r'^signup-success/$', views.signup_success,
name='billjobs_signup_success')
name='billjobs_signup_success'),
]
Loading

0 comments on commit e7e9011

Please sign in to comment.