Starting treasury app

This commit is contained in:
Yohann D'ANELLO 2020-03-21 00:30:49 +01:00
parent 1f004191a8
commit 71346476df
12 changed files with 197 additions and 0 deletions

View File

View File

11
apps/treasury/apps.py Normal file
View File

@ -0,0 +1,11 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.apps import AppConfig
from django.db.models.signals import pre_save, post_save, post_delete
from django.utils.translation import gettext_lazy as _
class TreasuryConfig(AppConfig):
name = 'treasury'
verbose_name = _('Treasury')

View File

113
apps/treasury/models.py Normal file
View File

@ -0,0 +1,113 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.db import models
from django.utils.translation import gettext_lazy as _
class Billing(models.Model):
id = models.PositiveIntegerField(
primary_key=True,
verbose_name=_("Billing identifier"),
)
subject = models.CharField(
max_length=255,
verbose_name=_("Subject"),
)
description = models.TextField(
verbose_name=_("Description")
)
name = models.CharField(
max_length=255,
verbose_name=_("Name"),
)
address = models.TextField(
verbose_name=_("Address"),
)
date = models.DateField(
auto_now_add=True,
verbose_name=_("Place"),
)
acquitted = models.BooleanField(
verbose_name=_("Acquitted"),
)
place = models.CharField(
max_length=255,
default="Cachan",
verbose_name=_("Place"),
)
my_name = models.CharField(
max_length=255,
default="BDE ENS Cachan",
verbose_name=_("My name"),
)
my_address_street = models.CharField(
max_length=255,
default="61 avenue du Président Wilson",
verbose_name=_("My street address"),
)
my_city = models.CharField(
max_length=255,
default="94230 Cachan",
verbose_name=_("My city"),
)
bank_code = models.IntegerField(
default=30003,
verbose_name=_("Bank code"),
)
desk_code = models.IntegerField(
default=3894,
verbose_name=_("Desk code"),
)
account_number = models.IntegerField(
default=37280662,
verbose_name=_("Account number"),
)
rib_key = models.SmallIntegerField(
default=14,
verbose_name=_("RIB Key")
)
bic = models.CharField(
max_length=16,
default="SOGEFRPP",
verbose_name=_("BIC Code")
)
class Product(models.Model):
billing = models.ForeignKey(
Billing,
on_delete=models.PROTECT,
)
designation = models.CharField(
max_length=255,
verbose_name=_("Designation"),
)
quantity = models.PositiveIntegerField(
verbose_name=_("Quantity")
)
amount = models.PositiveIntegerField(
verbose_name=_("Unit price")
)
@property
def total(self):
return self.quantity * self.amount

20
apps/treasury/tables.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django_tables2 import tables
from .models import Billing
class BillingTable(tables.Table):
class Meta:
attrs = {
'class': 'table table-condensed table-striped table-hover'
}
model = Billing
template_name = 'django_tables2/bootstrap4.html'
fields = ('id', 'name', 'subject', 'acquitted', )
row_attrs = {
'class': 'table-row',
'data-href': lambda record: record.pk
}

11
apps/treasury/urls.py Normal file
View File

@ -0,0 +1,11 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.urls import path
from .views import BillingListView
app_name = 'treasury'
urlpatterns = [
path('billing/', BillingListView.as_view(), name='billing'),
]

16
apps/treasury/views.py Normal file
View File

@ -0,0 +1,16 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.mixins import LoginRequiredMixin
from django_tables2 import SingleTableView
from .models import Billing
from .tables import BillingTable
class BillingListView(LoginRequiredMixin, SingleTableView):
"""
List existing Billings
"""
model = Billing
table_class = BillingTable

View File

@ -61,6 +61,7 @@ INSTALLED_APPS = [
'activity',
'member',
'note',
'treasury',
'api',
'logs',
]

View File

@ -13,6 +13,7 @@ urlpatterns = [
# Include project routers
path('note/', include('note.urls')),
path('treasury/', include('treasury.urls')),
# Include Django Contrib and Core routers
path('i18n/', include('django.conf.urls.i18n')),

View File

@ -81,6 +81,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
<li class="nav-item active">
<a class="nav-link" href="{% url 'note:transfer' %}"><i class="fa fa-exchange"></i>{% trans 'Transfer' %} </a>
</li>
<li class="nav-item active">
<a class="nav-link" href="{% url 'treasury:billing' %}"><i class="fa fa-money"></i>{% trans 'Treasury' %} </a>
</li>
</ul>
<ul class="navbar-nav ml-auto">
{% if user.is_authenticated %}

View File

@ -0,0 +1,21 @@
{% extends "base.html" %}
{% load render_table from django_tables2 %}
{% load i18n %}
{% block content %}
{% render_table table %}
<a class="btn btn-primary" href="{% url 'treasury:billing' %}">{% trans "New billing" %}</a>
{% endblock %}
{% block extrajavascript %}
<script type="text/javascript">
$(document).ready(function($) {
$(".table-row").click(function() {
window.document.location = $(this).data("href");
});
});
</script>
{% endblock %}