Add basic accounting views

This commit is contained in:
Skia 2016-04-20 03:01:14 +02:00
parent c6a3559bf5
commit 5fcb3e1412
8 changed files with 204 additions and 2 deletions

View File

@ -1,3 +1,4 @@
from django.core.urlresolvers import reverse
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
@ -71,6 +72,9 @@ class BankAccount(models.Model):
rib = models.CharField(_('rib'), max_length=255, blank=True)
number = models.CharField(_('account number'), max_length=255, blank=True)
def get_absolute_url(self):
return reverse('accounting:bank_details', kwargs={'b_account_id': self.id})
def __str__(self):
return self.name
@ -79,6 +83,9 @@ class ClubAccount(models.Model):
club = models.OneToOneField(Club, related_name="club_accounts")
bank_account = models.ForeignKey(BankAccount, related_name="club_accounts")
def get_absolute_url(self):
return reverse('accounting:club_details', kwargs={'c_account_id': self.id})
def __str__(self):
return self.name
@ -103,7 +110,7 @@ class AccountingType(models.Model):
"""
code = models.CharField(_('code'), max_length=16) # TODO: add number validator
label = models.CharField(_('label'), max_length=60)
movement_type = models.CharField(_('movement type'), choices=[('credit', 'Credit'), ('debit', 'Debit'), ('neutral', 'Neutral')])
movement_type = models.CharField(_('movement type'), choices=[('credit', 'Credit'), ('debit', 'Debit'), ('neutral', 'Neutral')], max_length=12)
class Operation(models.Model):
"""

View File

@ -0,0 +1,13 @@
{% extends "core/base.jinja" %}
{% block content %}
<h2>Edit account</h2>
<form action="" method="post">
{% csrf_token %}
{{ form.as_p() }}
<p><input type="submit" value="Save!" /></p>
</form>
{% endblock %}

View File

@ -0,0 +1,22 @@
{% extends "core/base.jinja" %}
{% block content %}
<h2>View account</h2>
<ul>
{% for k,v in object.__dict__.items() %}
<li>{{ k }} - {{ v }}</li>
{% endfor %}
</ul>
<p><a href="{{ url('accounting:club_new') }}">New club account</a></p>
<ul>
{% for c in object.club_accounts.all() %}
<li><a href="{{ url('accounting:club_details', c_account_id=c.id) }}">{{ c }}</a> -
<a href="{{ url('accounting:club_edit', c_account_id=c.id) }}">Edit</a> -
<a href="{{ url('accounting:club_delete', c_account_id=c.id) }}">Delete</a></li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -0,0 +1,24 @@
{% extends "core/base.jinja" %}
{% block title %}
Bank account list
{% endblock %}
{% block content %}
<p><a href="{{ url('accounting:bank_new') }}">New bank account</a></p>
{% if bankaccount_list %}
<h3>Bank account list</h3>
<ul>
{% for a in bankaccount_list %}
<li><a href="{{ url('accounting:bank_details', b_account_id=a.id) }}">{{ a }}</a> -
<a href="{{ url('accounting:bank_edit', b_account_id=a.id) }}">Edit</a> -
<a href="{{ url('accounting:bank_delete', b_account_id=a.id) }}">Delete</a></li>
{% endfor %}
</ul>
{% else %}
There is no accounts in this website.
{% endif %}
{% endblock %}

View File

@ -0,0 +1,20 @@
{% extends "core/base.jinja" %}
{% block content %}
<h2>View account: {{ object.name }}</h2>
<ul>
{% for k,v in object.__dict__.items() %}
<li>{{ k }} - {{ v }}</li>
{% endfor %}
</ul>
<p><a href="{{ url('accounting:journal_new') }}">New journal</a></p>
<ul>
{% for c in object.journals.all() %}
<li>{{ c }}</li>
{% endfor %}
</ul>
{% endblock %}

21
accounting/urls.py Normal file
View File

@ -0,0 +1,21 @@
from django.conf.urls import url, include
from accounting.views import *
urlpatterns = [
# Bank accounts
url(r'^$', BankAccountListView.as_view(), name='bank_list'),
url(r'^bank/create$', BankAccountCreateView.as_view(), name='bank_new'),
url(r'^bank/(?P<b_account_id>[0-9]+)$', BankAccountDetailView.as_view(), name='bank_details'),
url(r'^bank/(?P<b_account_id>[0-9]+)/edit$', BankAccountEditView.as_view(), name='bank_edit'),
url(r'^bank/(?P<b_account_id>[0-9]+)/delete$', BankAccountDeleteView.as_view(), name='bank_delete'),
# Club accounts
url(r'^club/create$', ClubAccountCreateView.as_view(), name='club_new'),
url(r'^club/(?P<c_account_id>[0-9]+)$', ClubAccountDetailView.as_view(), name='club_details'),
url(r'^club/(?P<c_account_id>[0-9]+)/edit$', ClubAccountEditView.as_view(), name='club_edit'),
url(r'^club/(?P<c_account_id>[0-9]+)/delete$', ClubAccountDeleteView.as_view(), name='club_delete'),
# Journals
url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'),
]

View File

@ -1,3 +1,97 @@
from django.views.generic import ListView, DetailView, RedirectView
from django.views.generic.edit import UpdateView, CreateView, DeleteView
from django.shortcuts import render
from django.core.urlresolvers import reverse_lazy
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation
# BankAccount views
class BankAccountListView(CanViewMixin, ListView):
"""
A list view for the admins
"""
model = BankAccount
template_name = 'accounting/bank_account_list.jinja'
class BankAccountEditView(CanViewMixin, UpdateView):
"""
An edit view for the admins
"""
model = BankAccount
pk_url_kwarg = "b_account_id"
fields = ['name', 'rib', 'number']
template_name = 'accounting/account_edit.jinja'
class BankAccountDetailView(CanViewMixin, DetailView):
"""
A detail view, listing every club account
"""
model = BankAccount
pk_url_kwarg = "b_account_id"
template_name = 'accounting/bank_account_details.jinja'
class BankAccountCreateView(CanEditMixin, CreateView):
"""
Create a bank account (for the admins)
"""
model = BankAccount
fields = ['name', 'rib', 'number']
template_name = 'accounting/account_edit.jinja'
class BankAccountDeleteView(CanEditMixin, DeleteView):
"""
Delete a bank account (for the admins)
"""
model = BankAccount
pk_url_kwarg = "b_account_id"
template_name = 'core/delete_confirm.jinja'
success_url = reverse_lazy('accounting:bank_list')
# ClubAccount views
class ClubAccountEditView(CanViewMixin, UpdateView):
"""
An edit view for the admins
"""
model = ClubAccount
pk_url_kwarg = "c_account_id"
fields = ['name', 'club', 'bank_account']
template_name = 'accounting/account_edit.jinja'
class ClubAccountDetailView(CanViewMixin, DetailView):
"""
A detail view, listing every journal
"""
model = ClubAccount
pk_url_kwarg = "c_account_id"
template_name = 'accounting/club_account_details.jinja'
class ClubAccountCreateView(CanEditMixin, CreateView):
"""
Create a club account (for the admins)
"""
model = ClubAccount
fields = ['name', 'club', 'bank_account']
template_name = 'accounting/account_edit.jinja'
class ClubAccountDeleteView(CanEditMixin, DeleteView):
"""
Delete a club account (for the admins)
"""
model = ClubAccount
pk_url_kwarg = "c_account_id"
template_name = 'core/delete_confirm.jinja'
success_url = reverse_lazy('accounting:bank_list')
# Journal views
class JournalCreateView(CanEditMixin, CreateView):
"""
Create a general journal
"""
model = GeneralJournal
fields = ['name']
template_name = 'accounting/account_edit.jinja'
# Create your views here.

View File

@ -26,5 +26,6 @@ urlpatterns = [
url(r'^subscription/', include('subscription.urls', namespace="subscription", app_name="subscription")),
url(r'^club/', include('club.urls', namespace="club", app_name="club")),
url(r'^counter/', include('counter.urls', namespace="counter", app_name="counter")),
url(r'^accounting/', include('accounting.urls', namespace="accounting", app_name="accounting")),
url(r'^admin/', include(admin.site.urls)),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # TODO: remove me for production!!!