Add first accounting implementation

This commit is contained in:
Skia
2016-01-28 16:53:37 +01:00
parent 2b999d87ba
commit f71ce2f7df
12 changed files with 245 additions and 4 deletions

0
accounting/__init__.py Normal file
View File

12
accounting/admin.py Normal file
View File

@ -0,0 +1,12 @@
from django.contrib import admin
from accounting.models import *
admin.site.register(Customer)
admin.site.register(ProductType)
admin.site.register(Product)
admin.site.register(GeneralJournal)
admin.site.register(GenericInvoice)

View File

@ -0,0 +1,72 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
import accounting.models
class Migration(migrations.Migration):
dependencies = [
('core', '0005_auto_20160128_0842'),
]
operations = [
migrations.CreateModel(
name='Customer',
fields=[
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL, primary_key=True, serialize=False)),
('account_id', models.CharField(unique=True, verbose_name='account id', max_length=10)),
],
options={
'verbose_name': 'customer',
'verbose_name_plural': 'customers',
},
),
migrations.CreateModel(
name='GeneralJournal',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)),
('start_date', models.DateField(verbose_name='start date')),
('end_date', models.DateField(null=True, verbose_name='end date', blank=True, default=None)),
('name', models.CharField(verbose_name='name', max_length=30)),
('closed', models.BooleanField(default=False, verbose_name='is closed')),
],
),
migrations.CreateModel(
name='GenericInvoice',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)),
('name', models.CharField(verbose_name='name', max_length=100)),
('journal', models.ForeignKey(to='accounting.GeneralJournal', related_name='invoices')),
],
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)),
('name', models.CharField(verbose_name='name', max_length=30)),
('description', models.TextField(verbose_name='description')),
('code', models.CharField(verbose_name='code', max_length=10)),
('purchase_price', accounting.models.CurrencyField(max_digits=12, decimal_places=2, verbose_name='purchase price')),
('selling_price', accounting.models.CurrencyField(max_digits=12, decimal_places=2, verbose_name='selling price')),
('special_selling_price', accounting.models.CurrencyField(max_digits=12, decimal_places=2, verbose_name='special selling price')),
('icon', models.ImageField(null=True, upload_to='products')),
],
),
migrations.CreateModel(
name='ProductType',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)),
('name', models.CharField(verbose_name='name', max_length=30)),
('description', models.TextField(verbose_name='description')),
('icon', models.ImageField(null=True, upload_to='products')),
],
),
migrations.AddField(
model_name='product',
name='product_type',
field=models.ForeignKey(null=True, to='accounting.ProductType', related_name='products'),
),
]

View File

@ -0,0 +1,39 @@
# -*- 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='product',
name='description',
field=models.TextField(verbose_name='description', blank=True),
),
migrations.AlterField(
model_name='product',
name='icon',
field=models.ImageField(null=True, upload_to='products', blank=True),
),
migrations.AlterField(
model_name='product',
name='product_type',
field=models.ForeignKey(to='accounting.ProductType', null=True, blank=True, related_name='products'),
),
migrations.AlterField(
model_name='producttype',
name='description',
field=models.TextField(verbose_name='description', null=True, blank=True),
),
migrations.AlterField(
model_name='producttype',
name='icon',
field=models.ImageField(null=True, upload_to='products', blank=True),
),
]

View File

94
accounting/models.py Normal file
View File

@ -0,0 +1,94 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from decimal import Decimal
from core.models import User
class CurrencyField(models.DecimalField):
"""
This is a custom database field used for currency
"""
__metaclass__ = models.SubfieldBase
def __init__(self, *args, **kwargs):
kwargs['max_digits'] = 12
kwargs['decimal_places'] = 2
super(CurrencyField, self).__init__(*args, **kwargs)
def to_python(self, value):
try:
return super(CurrencyField, self).to_python(value).quantize(Decimal("0.01"))
except AttributeError:
return None
class Customer(models.Model):
"""
This class extends a user to make a customer. It adds some basic customers informations, such as the accound ID, and
is used by other accounting classes as reference to the customer, rather than using User
"""
user = models.OneToOneField(User, primary_key=True)
account_id = models.CharField(_('account id'), max_length=10, unique=True)
class Meta:
verbose_name = _('customer')
verbose_name_plural = _('customers')
def __str__(self):
return self.user.username
class ProductType(models.Model):
"""
This describes a product type
Useful only for categorizing, changes are made at the product level
"""
name = models.CharField(_('name'), max_length=30)
description = models.TextField(_('description'), null=True, blank=True)
icon = models.ImageField(upload_to='products', null=True, blank=True)
def __str__(self):
return self.name
class Product(models.Model):
"""
This describes a product, with all its related informations
"""
name = models.CharField(_('name'), max_length=30)
description = models.TextField(_('description'), blank=True)
product_type = models.ForeignKey(ProductType, related_name='products', null=True, blank=True)
code = models.CharField(_('code'), max_length=10)
purchase_price = CurrencyField(_('purchase price'))
selling_price = CurrencyField(_('selling price'))
special_selling_price = CurrencyField(_('special selling price'))
icon = models.ImageField(upload_to='products', null=True, blank=True)
def __str__(self):
return self.name
class GeneralJournal(models.Model):
"""
Class storing all the invoices 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)
def __str__(self):
return self.name
class GenericInvoice(models.Model):
"""
This class is a generic invoice, made to be extended with some special cases (eg: for the internal accounting, payment
system, etc...)
"""
journal = models.ForeignKey(GeneralJournal, related_name="invoices", null=False)
name = models.CharField(_('name'), max_length=100)
def __str__(self):
return self.journal.name+' - '+self.name
# TODO: CountingInvoice in Counting app extending GenericInvoice
# - ManyToMany Product

3
accounting/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

3
accounting/views.py Normal file
View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.