mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
"Finish" the accounting views
This commit is contained in:
parent
9c0b17a9ae
commit
6e05207e84
@ -9,6 +9,7 @@ admin.site.register(Product)
|
|||||||
admin.site.register(BankAccount)
|
admin.site.register(BankAccount)
|
||||||
admin.site.register(ClubAccount)
|
admin.site.register(ClubAccount)
|
||||||
admin.site.register(GeneralJournal)
|
admin.site.register(GeneralJournal)
|
||||||
|
admin.site.register(AccountingType)
|
||||||
admin.site.register(Operation)
|
admin.site.register(Operation)
|
||||||
|
|
||||||
|
|
||||||
|
19
accounting/migrations/0002_auto_20160502_0952.py
Normal file
19
accounting/migrations/0002_auto_20160502_0952.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- 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):
|
def __str__(self):
|
||||||
return self.user.username
|
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
|
This describes a product type
|
||||||
Useful only for categorizing, changes are made at the product level for now
|
Useful only for categorizing, changes are made at the product level for now
|
||||||
@ -51,7 +63,7 @@ class ProductType(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class Product(models.Model):
|
class Product(models.Model, AccountingMixin):
|
||||||
"""
|
"""
|
||||||
This describes a product, with all its related informations
|
This describes a product, with all its related informations
|
||||||
"""
|
"""
|
||||||
@ -67,7 +79,7 @@ class Product(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class BankAccount(models.Model):
|
class BankAccount(models.Model, AccountingMixin):
|
||||||
name = models.CharField(_('name'), max_length=30)
|
name = models.CharField(_('name'), max_length=30)
|
||||||
rib = models.CharField(_('rib'), max_length=255, blank=True)
|
rib = models.CharField(_('rib'), max_length=255, blank=True)
|
||||||
number = models.CharField(_('account number'), 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):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class ClubAccount(models.Model):
|
class ClubAccount(models.Model, AccountingMixin):
|
||||||
name = models.CharField(_('name'), max_length=30)
|
name = models.CharField(_('name'), max_length=30)
|
||||||
club = models.OneToOneField(Club, related_name="club_accounts")
|
club = models.OneToOneField(Club, related_name="club_accounts")
|
||||||
bank_account = models.ForeignKey(BankAccount, related_name="club_accounts")
|
bank_account = models.ForeignKey(BankAccount, related_name="club_accounts")
|
||||||
@ -89,7 +101,7 @@ class ClubAccount(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class GeneralJournal(models.Model):
|
class GeneralJournal(models.Model, AccountingMixin):
|
||||||
"""
|
"""
|
||||||
Class storing all the operations for a period of time
|
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)
|
closed = models.BooleanField(_('is closed'), default=False)
|
||||||
club_account = models.ForeignKey(ClubAccount, related_name="journals", null=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):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
class AccountingType(models.Model):
|
class AccountingType(models.Model, AccountingMixin):
|
||||||
"""
|
"""
|
||||||
Class describing the accounting types.
|
Class describing the accounting types.
|
||||||
|
|
||||||
@ -112,11 +127,17 @@ class AccountingType(models.Model):
|
|||||||
label = models.CharField(_('label'), max_length=60)
|
label = models.CharField(_('label'), max_length=60)
|
||||||
movement_type = models.CharField(_('movement type'), choices=[('credit', 'Credit'), ('debit', 'Debit'), ('neutral', 'Neutral')], max_length=12)
|
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
|
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'))
|
date = models.DateField(_('date'))
|
||||||
remark = models.TextField(_('remark'), max_length=255)
|
remark = models.TextField(_('remark'), max_length=255)
|
||||||
mode = models.CharField(_('payment method'), max_length=255, choices=settings.SITH_ACCOUNTING_PAYMENT_METHOD)
|
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)
|
done = models.BooleanField(_('is done'), default=False)
|
||||||
type = models.ForeignKey(AccountingType, related_name="operations")
|
type = models.ForeignKey(AccountingType, related_name="operations")
|
||||||
|
|
||||||
def __str__(self):
|
def get_absolute_url(self):
|
||||||
return self.journal.name+' - '+self.name
|
return reverse('accounting:journal_details', kwargs={'j_id': self.journal.id})
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.id)+" - "+str(self.date)
|
||||||
|
|
||||||
|
23
accounting/templates/accounting/accountingtype_list.jinja
Normal file
23
accounting/templates/accounting/accountingtype_list.jinja
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
{% 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 %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% 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>
|
<p><a href="{{ url('accounting:bank_new') }}">New bank account</a></p>
|
||||||
{% if bankaccount_list %}
|
{% if bankaccount_list %}
|
||||||
<h3>Bank account list</h3>
|
<h3>Bank account list</h3>
|
||||||
|
@ -9,8 +9,12 @@
|
|||||||
</ul>
|
</ul>
|
||||||
<p><a href="{{ url('accounting:journal_new') }}">New journal</a></p>
|
<p><a href="{{ url('accounting:journal_new') }}">New journal</a></p>
|
||||||
<ul>
|
<ul>
|
||||||
{% for c in object.journals.all() %}
|
{% for j in object.journals.all() %}
|
||||||
<li>{{ c }}</li>
|
<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 %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
22
accounting/templates/accounting/journal_details.jinja
Normal file
22
accounting/templates/accounting/journal_details.jinja
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{% 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 *
|
from accounting.views import *
|
||||||
|
|
||||||
urlpatterns = [
|
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
|
# Bank accounts
|
||||||
url(r'^$', BankAccountListView.as_view(), name='bank_list'),
|
url(r'^$', BankAccountListView.as_view(), name='bank_list'),
|
||||||
url(r'^bank/create$', BankAccountCreateView.as_view(), name='bank_new'),
|
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'),
|
url(r'^club/(?P<c_account_id>[0-9]+)/delete$', ClubAccountDeleteView.as_view(), name='club_delete'),
|
||||||
# Journals
|
# Journals
|
||||||
url(r'^journal/create$', JournalCreateView.as_view(), name='journal_new'),
|
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 django.core.urlresolvers import reverse_lazy
|
||||||
|
|
||||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
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
|
# BankAccount views
|
||||||
|
|
||||||
@ -92,6 +118,42 @@ class JournalCreateView(CanEditMixin, CreateView):
|
|||||||
Create a general journal
|
Create a general journal
|
||||||
"""
|
"""
|
||||||
model = GeneralJournal
|
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'
|
template_name = 'accounting/account_edit.jinja'
|
||||||
|
|
||||||
|
@ -266,7 +266,9 @@ class AnonymousUser(AuthAnonymousUser):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def can_view(self, obj):
|
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 True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
{% if user.is_authenticated() %}
|
{% if user.is_authenticated() %}
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{{ url('core:user_profile', user_id=user.id) }}">Profile</a></li>
|
<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:user_list') }}">Users</a></li>
|
||||||
<li><a href="{{ url('core:page', page_name="Index") }}">Pages</a></li>
|
<li><a href="{{ url('core:page', page_name="Index") }}">Pages</a></li>
|
||||||
<li><a href="{{ url('club:club_list') }}">Clubs</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']) %}
|
{% if user.is_in_group(settings.SITH_GROUPS['root']['name']) %}
|
||||||
<li><a href="{{ url('core:group_list') }}">Groups</a></li>
|
<li><a href="{{ url('core:group_list') }}">Groups</a></li>
|
||||||
{% endif %}
|
{% 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) %}
|
{% 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('subscription:subscription') }}">Subscriptions</a></li>
|
||||||
<li><a href="{{ url('counter:admin_list') }}">Counters management</a></li>
|
<li><a href="{{ url('counter:admin_list') }}">Counters management</a></li>
|
||||||
|
@ -189,9 +189,13 @@ SITH_GROUPS = {
|
|||||||
'id': 1,
|
'id': 1,
|
||||||
'name': "root",
|
'name': "root",
|
||||||
},
|
},
|
||||||
'public': {
|
'accounting-admin': {
|
||||||
'id': 2,
|
'id': 2,
|
||||||
'name': "not_registered_users",
|
'name': "accounting-admin",
|
||||||
|
},
|
||||||
|
'public': {
|
||||||
|
'id': 3,
|
||||||
|
'name': "not-registered-users",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user