Improve accounting model according to current site's one

This commit is contained in:
Skia
2016-04-20 02:07:01 +02:00
parent 9a135ade50
commit c6a3559bf5
9 changed files with 144 additions and 52 deletions

View File

@ -6,7 +6,9 @@ from accounting.models import *
admin.site.register(Customer)
admin.site.register(ProductType)
admin.site.register(Product)
admin.site.register(BankAccount)
admin.site.register(ClubAccount)
admin.site.register(GeneralJournal)
admin.site.register(GenericInvoice)
admin.site.register(Operation)

View File

@ -2,71 +2,91 @@
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import accounting.models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('club', '__first__'),
('core', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='BankAccount',
fields=[
('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
('name', models.CharField(verbose_name='name', max_length=30)),
('rib', models.CharField(verbose_name='rib', max_length=255)),
('number', models.CharField(verbose_name='account number', max_length=255)),
],
),
migrations.CreateModel(
name='ClubAccount',
fields=[
('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
('name', models.CharField(verbose_name='name', max_length=30)),
('bank_account', models.ForeignKey(related_name='club_accounts', to='accounting.BankAccount')),
('club', models.OneToOneField(related_name='club_accounts', to='club.Club')),
],
),
migrations.CreateModel(
name='Customer',
fields=[
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL, serialize=False, primary_key=True)),
('account_id', models.CharField(max_length=10, verbose_name='account id', unique=True)),
('user', models.OneToOneField(primary_key=True, to=settings.AUTH_USER_MODEL, serialize=False)),
('account_id', models.CharField(verbose_name='account id', unique=True, max_length=10)),
],
options={
'verbose_name': 'customer',
'verbose_name_plural': 'customers',
'verbose_name': 'customer',
},
),
migrations.CreateModel(
name='GeneralJournal',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
('start_date', models.DateField(verbose_name='start date')),
('end_date', models.DateField(default=None, blank=True, null=True, verbose_name='end date')),
('name', models.CharField(max_length=30, verbose_name='name')),
('end_date', models.DateField(default=None, verbose_name='end date', null=True, blank=True)),
('name', models.CharField(verbose_name='name', max_length=30)),
('closed', models.BooleanField(default=False, verbose_name='is closed')),
('club_account', models.ForeignKey(related_name='journals', to='accounting.ClubAccount')),
],
),
migrations.CreateModel(
name='GenericInvoice',
name='Operation',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('name', models.CharField(max_length=100, verbose_name='name')),
('journal', models.ForeignKey(to='accounting.GeneralJournal', related_name='invoices')),
('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
('name', models.CharField(verbose_name='name', max_length=100)),
('journal', models.ForeignKey(related_name='invoices', to='accounting.GeneralJournal')),
],
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('name', models.CharField(max_length=30, verbose_name='name')),
('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
('name', models.CharField(verbose_name='name', max_length=30)),
('description', models.TextField(blank=True, verbose_name='description')),
('code', models.CharField(max_length=10, verbose_name='code')),
('purchase_price', accounting.models.CurrencyField(max_digits=12, verbose_name='purchase price', decimal_places=2)),
('selling_price', accounting.models.CurrencyField(max_digits=12, verbose_name='selling price', decimal_places=2)),
('special_selling_price', accounting.models.CurrencyField(max_digits=12, verbose_name='special selling price', decimal_places=2)),
('icon', models.ImageField(upload_to='products', blank=True, null=True)),
('code', models.CharField(verbose_name='code', max_length=10)),
('purchase_price', accounting.models.CurrencyField(verbose_name='purchase price', decimal_places=2, max_digits=12)),
('selling_price', accounting.models.CurrencyField(verbose_name='selling price', decimal_places=2, max_digits=12)),
('special_selling_price', accounting.models.CurrencyField(verbose_name='special selling price', decimal_places=2, max_digits=12)),
('icon', models.ImageField(blank=True, null=True, upload_to='products')),
],
),
migrations.CreateModel(
name='ProductType',
fields=[
('id', models.AutoField(primary_key=True, serialize=False, verbose_name='ID', auto_created=True)),
('name', models.CharField(max_length=30, verbose_name='name')),
('description', models.TextField(blank=True, null=True, verbose_name='description')),
('icon', models.ImageField(upload_to='products', blank=True, null=True)),
('id', models.AutoField(auto_created=True, verbose_name='ID', serialize=False, primary_key=True)),
('name', models.CharField(verbose_name='name', max_length=30)),
('description', models.TextField(blank=True, verbose_name='description', null=True)),
('icon', models.ImageField(blank=True, null=True, upload_to='products')),
],
),
migrations.AddField(
model_name='product',
name='product_type',
field=models.ForeignKey(blank=True, related_name='products', to='accounting.ProductType', null=True),
field=models.ForeignKey(blank=True, related_name='products', null=True, to='accounting.ProductType'),
),
]

View File

@ -0,0 +1,24 @@
# -*- 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='bankaccount',
name='number',
field=models.CharField(max_length=255, blank=True, verbose_name='account number'),
),
migrations.AlterField(
model_name='bankaccount',
name='rib',
field=models.CharField(max_length=255, blank=True, verbose_name='rib'),
),
]

View File

@ -1,8 +1,10 @@
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from decimal import Decimal
from core.models import User
from club.models import Club
class CurrencyField(models.DecimalField):
"""
@ -64,31 +66,58 @@ class Product(models.Model):
def __str__(self):
return self.name
class BankAccount(models.Model):
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)
def __str__(self):
return self.name
class ClubAccount(models.Model):
name = models.CharField(_('name'), max_length=30)
club = models.OneToOneField(Club, related_name="club_accounts")
bank_account = models.ForeignKey(BankAccount, related_name="club_accounts")
def __str__(self):
return self.name
class GeneralJournal(models.Model):
"""
Class storing all the invoices for a period of time
Class storing all the operations for a period of time
"""
start_date = models.DateField(_('start date'))
end_date = models.DateField(_('end date'), null=True, blank=True, default=None)
name = models.CharField(_('name'), max_length=30)
closed = models.BooleanField(_('is closed'), default=False)
# When clubs are done: ForeignKey(Proprietary)
club_account = models.ForeignKey(ClubAccount, related_name="journals", null=False)
def __str__(self):
return self.name
class GenericInvoice(models.Model):
class AccountingType(models.Model):
"""
This class is a generic invoice, made to be extended with some special cases (eg: for the internal accounting, payment
system, etc...)
Class describing the accounting types.
Thoses are numbers used in accounting to classify operations
"""
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')])
class Operation(models.Model):
"""
An operation is a line in the journal, a debit or a credit
"""
journal = models.ForeignKey(GeneralJournal, related_name="invoices", null=False)
name = models.CharField(_('name'), max_length=100)
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)
cheque_number = models.IntegerField(_('cheque number'))
invoice = models.FileField(upload_to='invoices', null=True, blank=True)
done = models.BooleanField(_('is done'), default=False)
type = models.ForeignKey(AccountingType, related_name="operations")
def __str__(self):
return self.journal.name+' - '+self.name
# TODO: CountingInvoice in Counting app extending GenericInvoice
# - ManyToMany Product