Commit 6e05207e authored by Skia's avatar Skia

"Finish" the accounting views

parent 9c0b17a9
Pipeline #21 passed with stage
......@@ -9,6 +9,7 @@ admin.site.register(Product)
admin.site.register(BankAccount)
admin.site.register(ClubAccount)
admin.site.register(GeneralJournal)
admin.site.register(AccountingType)
admin.site.register(Operation)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('accounting', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='operation',
name='journal',
field=models.ForeignKey(to='accounting.GeneralJournal', related_name='operations'),
),
]
......@@ -39,7 +39,19 @@ class Customer(models.Model):
def __str__(self):
return self.user.username
class ProductType(models.Model):
class AccountingMixin():
"""
Mixin providing the rights managment for all accounting classes
"""
def can_be_edited_by(self, user):
"""
Method to see if that object can be edited by the given user
"""
if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']):
return True
return False
class ProductType(models.Model, AccountingMixin):
"""
This describes a product type
Useful only for categorizing, changes are made at the product level for now
......@@ -51,7 +63,7 @@ class ProductType(models.Model):
def __str__(self):
return self.name
class Product(models.Model):
class Product(models.Model, AccountingMixin):
"""
This describes a product, with all its related informations
"""
......@@ -67,7 +79,7 @@ class Product(models.Model):
def __str__(self):
return self.name
class BankAccount(models.Model):
class BankAccount(models.Model, AccountingMixin):
name = models.CharField(_('name'), max_length=30)
rib = models.CharField(_('rib'), max_length=255, blank=True)
number = models.CharField(_('account number'), max_length=255, blank=True)
......@@ -78,7 +90,7 @@ class BankAccount(models.Model):
def __str__(self):
return self.name
class ClubAccount(models.Model):
class ClubAccount(models.Model, AccountingMixin):
name = models.CharField(_('name'), max_length=30)
club = models.OneToOneField(Club, related_name="club_accounts")
bank_account = models.ForeignKey(BankAccount, related_name="club_accounts")
......@@ -89,7 +101,7 @@ class ClubAccount(models.Model):
def __str__(self):
return self.name
class GeneralJournal(models.Model):
class GeneralJournal(models.Model, AccountingMixin):
"""
Class storing all the operations for a period of time
"""
......@@ -99,10 +111,13 @@ class GeneralJournal(models.Model):
closed = models.BooleanField(_('is closed'), default=False)
club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False)
def get_absolute_url(self):
return reverse('accounting:journal_details', kwargs={'j_id': self.id})
def __str__(self):
return self.name
class AccountingType(models.Model):
class AccountingType(models.Model, AccountingMixin):
"""
Class describing the accounting types.
......@@ -112,11 +127,17 @@ class AccountingType(models.Model):
label = models.CharField(_('label'), max_length=60)
movement_type = models.CharField(_('movement type'), choices=[('credit', 'Credit'), ('debit', 'Debit'), ('neutral', 'Neutral')], max_length=12)
class Operation(models.Model):
def get_absolute_url(self):
return reverse('accounting:type_list')
def __str__(self):
return self.movement_type+" - "+self.code+" - "+self.label
class Operation(models.Model, AccountingMixin):
"""
An operation is a line in the journal, a debit or a credit
"""
journal = models.ForeignKey(GeneralJournal, related_name="invoices", null=False)
journal = models.ForeignKey(GeneralJournal, related_name="operations", null=False)
date = models.DateField(_('date'))
remark = models.TextField(_('remark'), max_length=255)
mode = models.CharField(_('payment method'), max_length=255, choices=settings.SITH_ACCOUNTING_PAYMENT_METHOD)
......@@ -125,6 +146,9 @@ class Operation(models.Model):
done = models.BooleanField(_('is done'), default=False)
type = models.ForeignKey(AccountingType, related_name="operations")
def get_absolute_url(self):
return reverse('accounting:journal_details', kwargs={'j_id': self.journal.id})
def __str__(self):
return self.journal.name+' - '+self.name
return str(self.id)+" - "+str(self.date)
{% extends "core/base.jinja" %}
{% block title %}
Accounting type list
{% endblock %}
{% block content %}
<p><a href="{{ url('accounting:type_new') }}">New accounting type</a></p>
{% if accountingtype_list %}
<h3>Accounting type list</h3>
<ul>
{% for a in accountingtype_list %}
<li><a href="{{ url('accounting:type_edit', type_id=a.id) }}">{{ a }}</a></li>
{% endfor %}
</ul>
{% else %}
There is no types in this website.
{% endif %}
{% endblock %}
......@@ -5,6 +5,7 @@
{% endblock %}
{% block content %}
<p><a href="{{ url('accounting:type_list') }}">Manage accounting types</a></p>
<p><a href="{{ url('accounting:bank_new') }}">New bank account</a></p>
{% if bankaccount_list %}
<h3>Bank account list</h3>
......
......@@ -9,8 +9,12 @@
</ul>
<p><a href="{{ url('accounting:journal_new') }}">New journal</a></p>
<ul>
{% for c in object.journals.all() %}
<li>{{ c }}</li>
{% for j in object.journals.all() %}
<li>
<a href="{{ url('accounting:journal_details', j_id=j.id) }}">{{ j }}</a> -
<a href="{{ url('accounting:journal_edit', j_id=j.id) }}">Edit</a>
</li>
{% endfor %}
</ul>
......
{% extends "core/base.jinja" %}
{% block content %}
<h2>View journal: {{ object.name }}</h2>
<ul>
{% for k,v in object.__dict__.items() %}
<li>{{ k }} - {{ v }}</li>
{% endfor %}
</ul>
<p><a href="{{ url('accounting:op_new') }}">New operation</a></p>
<ul>
{% for o in object.operations.all() %}
<li>
<a href="{{ url('accounting:op_edit', op_id=o.id) }}">{{ o }}</a>
</li>
{% endfor %}
</ul>
{% endblock %}
......@@ -3,6 +3,10 @@ from django.conf.urls import url, include
from accounting.views import *
urlpatterns = [
# Accounting types
url(r'^type$', AccountingTypeListView.as_view(), name='type_list'),
url(r'^type/create$', AccountingTypeCreateView.as_view(), name='type_new'),
url(r'^type/(?P<type_id>[0-9]+)/edit$', AccountingTypeEditView.as_view(), name='type_edit'),
# Bank accounts
url(r'^$', BankAccountListView.as_view(), name='bank_list'),
url(r'^bank/create$', BankAccountCreateView.as_view(), name='bank_new'),
......@@ -16,6 +20,11 @@ urlpatterns = [
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'),
url(r'^journal/(?P<j_id>[0-9]+)$', JournalDetailView.as_view(), name='journal_details'),
url(r'^journal/(?P<j_id>[0-9]+)/edit$', JournalEditView.as_view(), name='journal_edit'),
# Operations
url(r'^operation/create$', OperationCreateView.as_view(), name='op_new'),
url(r'^operation/(?P<op_id>[0-9]+)$', OperationEditView.as_view(), name='op_edit'),
]
......@@ -4,7 +4,33 @@ 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
from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType
# Accounting types
class AccountingTypeListView(CanViewMixin, ListView):
"""
A list view for the admins
"""
model = AccountingType
template_name = 'accounting/accountingtype_list.jinja'
class AccountingTypeEditView(CanViewMixin, UpdateView):
"""
An edit view for the admins
"""
model = AccountingType
pk_url_kwarg = "type_id"
fields = ['code', 'label', 'movement_type']
template_name = 'accounting/account_edit.jinja'
class AccountingTypeCreateView(CanEditMixin, CreateView):
"""
Create an accounting type (for the admins)
"""
model = AccountingType
fields = ['code', 'label', 'movement_type']
template_name = 'accounting/account_edit.jinja'
# BankAccount views
......@@ -92,6 +118,42 @@ class JournalCreateView(CanEditMixin, CreateView):
Create a general journal
"""
model = GeneralJournal
fields = ['name']
fields = ['name', 'start_date', 'club_account']
template_name = 'accounting/account_edit.jinja'
class JournalDetailView(CanViewMixin, DetailView):
"""
A detail view, listing every operation
"""
model = GeneralJournal
pk_url_kwarg = "j_id"
template_name = 'accounting/journal_details.jinja'
class JournalEditView(CanEditMixin, UpdateView):
"""
Update a general journal
"""
model = GeneralJournal
pk_url_kwarg = "j_id"
fields = ['name', 'start_date', 'club_account']
template_name = 'accounting/account_edit.jinja'
# Operation views
class OperationCreateView(CanEditMixin, CreateView):
"""
Create an operation
"""
model = Operation
fields = ['journal', 'date', 'cheque_number', 'type']
template_name = 'accounting/account_edit.jinja'
class OperationEditView(CanViewMixin, UpdateView):
"""
An edit view, working as detail for the moment
"""
model = Operation
pk_url_kwarg = "op_id"
fields = ['journal', 'date', 'cheque_number', 'type']
template_name = 'accounting/account_edit.jinja'
......@@ -266,7 +266,9 @@ class AnonymousUser(AuthAnonymousUser):
return False
def can_view(self, obj):
if obj.view_groups.filter(pk=settings.SITH_GROUPS['public']['id']).exists():
if hasattr(obj, 'view_groups') and obj.view_groups.filter(pk=settings.SITH_GROUPS['public']['id']).exists():
return True
if hasattr(obj, 'can_be_viewed_by') and obj.can_be_viewed_by(self):
return True
return False
......
......@@ -24,6 +24,7 @@
{% if user.is_authenticated() %}
<ul>
<li><a href="{{ url('core:user_profile', user_id=user.id) }}">Profile</a></li>
<li><a href="{{ url('core:user_tools') }}">Tools</a></li>
<li><a href="{{ url('core:user_list') }}">Users</a></li>
<li><a href="{{ url('core:page', page_name="Index") }}">Pages</a></li>
<li><a href="{{ url('club:club_list') }}">Clubs</a></li>
......
......@@ -12,6 +12,9 @@
{% if user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
<li><a href="{{ url('core:group_list') }}">Groups</a></li>
{% endif %}
{% if user.is_in_group(settings.SITH_GROUPS['accounting-admin']['name']) %}
<li><a href="{{ url('accounting:bank_list') }}">Accounting</a></li>
{% endif %}
{% if user.is_in_group(settings.SITH_GROUPS['root']['name']) or user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) %}
<li><a href="{{ url('subscription:subscription') }}">Subscriptions</a></li>
<li><a href="{{ url('counter:admin_list') }}">Counters management</a></li>
......
......@@ -189,9 +189,13 @@ SITH_GROUPS = {
'id': 1,
'name': "root",
},
'public': {
'accounting-admin': {
'id': 2,
'name': "not_registered_users",
'name': "accounting-admin",
},
'public': {
'id': 3,
'name': "not-registered-users",
},
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment