mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-10 03:49:24 +00:00
Some refactoring between accounting and counter
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from counter.models import Counter
|
||||
from counter.models import *
|
||||
|
||||
# Register your models here.
|
||||
admin.site.register(Customer)
|
||||
admin.site.register(ProductType)
|
||||
admin.site.register(Product)
|
||||
admin.site.register(Counter)
|
||||
|
@ -2,6 +2,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import accounting.models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
@ -9,20 +11,66 @@ class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('club', '0001_initial'),
|
||||
('core', '0001_initial'),
|
||||
('accounting', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Counter',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
('name', models.CharField(max_length=30, verbose_name='name')),
|
||||
('type', models.CharField(max_length=255, verbose_name='subscription type', choices=[('BAR', 'Bar'), ('OFFICE', 'Office')])),
|
||||
('type', models.CharField(choices=[('BAR', 'Bar'), ('OFFICE', 'Office')], max_length=255, verbose_name='subscription type')),
|
||||
('club', models.ForeignKey(to='club.Club', related_name='counters')),
|
||||
('edit_groups', models.ManyToManyField(blank=True, related_name='editable_counters', to='core.Group')),
|
||||
('products', models.ManyToManyField(blank=True, related_name='counters', to='accounting.Product')),
|
||||
('view_groups', models.ManyToManyField(blank=True, related_name='viewable_counters', to='core.Group')),
|
||||
('edit_groups', models.ManyToManyField(related_name='editable_counters', to='core.Group', blank=True)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Customer',
|
||||
fields=[
|
||||
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL, primary_key=True, serialize=False)),
|
||||
('account_id', models.CharField(unique=True, max_length=10, verbose_name='account id')),
|
||||
],
|
||||
options={
|
||||
'verbose_name_plural': 'customers',
|
||||
'verbose_name': 'customer',
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Product',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
('name', models.CharField(max_length=30, verbose_name='name')),
|
||||
('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, 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(blank=True, upload_to='products', null=True)),
|
||||
('club', models.ForeignKey(to='club.Club', related_name='products')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='ProductType',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
('name', models.CharField(max_length=30, verbose_name='name')),
|
||||
('description', models.TextField(blank=True, verbose_name='description', null=True)),
|
||||
('icon', models.ImageField(blank=True, upload_to='products', null=True)),
|
||||
],
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='product',
|
||||
name='product_type',
|
||||
field=models.ForeignKey(to='counter.ProductType', related_name='products', null=True, blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='counter',
|
||||
name='products',
|
||||
field=models.ManyToManyField(related_name='counters', to='counter.Product', blank=True),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='counter',
|
||||
name='view_groups',
|
||||
field=models.ManyToManyField(related_name='viewable_counters', to='core.Group', blank=True),
|
||||
),
|
||||
]
|
||||
|
@ -7,10 +7,70 @@ from django.core.urlresolvers import reverse
|
||||
from datetime import timedelta
|
||||
|
||||
from club.models import Club
|
||||
from accounting.models import Product
|
||||
from core.models import Group
|
||||
from accounting.models import CurrencyField
|
||||
from core.models import Group, User
|
||||
from subscription.models import Subscriber
|
||||
|
||||
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 for now
|
||||
"""
|
||||
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 is_owned_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
|
||||
|
||||
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)
|
||||
club = models.ForeignKey(Club, related_name="products")
|
||||
|
||||
def is_owned_by(self, user): # TODO do this for all models
|
||||
"""
|
||||
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
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Counter(models.Model):
|
||||
name = models.CharField(_('name'), max_length=30)
|
||||
club = models.ForeignKey(Club, related_name="counters")
|
||||
@ -48,3 +108,9 @@ class Counter(models.Model):
|
||||
Counter.barmen_session[counter_id]['users'] = set()
|
||||
return bl
|
||||
|
||||
|
||||
# TODO:
|
||||
# une classe Vente
|
||||
# foreign key vers comptoir, vendeur, client, produit, mais stocker le prix du produit, pour gerer les maj de prix
|
||||
# une classe Rechargement
|
||||
# foreign key vers comptoir, vendeur, client, plus montant
|
||||
|
@ -12,8 +12,7 @@ from django import forms
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
||||
from subscription.models import Subscriber
|
||||
from accounting.models import Customer, Product
|
||||
from counter.models import Counter
|
||||
from counter.models import Counter, Customer, Product
|
||||
|
||||
class GetUserForm(forms.Form):
|
||||
"""
|
||||
|
Reference in New Issue
Block a user