mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-17 19:53:21 +00:00
Add Selling and Refilling classes
This commit is contained in:
parent
356a2d2683
commit
6c48b7c718
@ -8,7 +8,7 @@ from core.models import Group, User, Page, PageRev
|
||||
from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType
|
||||
from club.models import Club, Membership
|
||||
from subscription.models import Subscription, Subscriber
|
||||
from counter.models import Customer, ProductType, Product
|
||||
from counter.models import Customer, ProductType, Product, Counter
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Populate a new instance of the Sith AE"
|
||||
@ -138,18 +138,27 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
|
||||
address="Terre Du Milieu", parent=ae)
|
||||
troll.save()
|
||||
|
||||
# Accounting test values:
|
||||
Customer(user=skia, account_id="6568j").save()
|
||||
# Counters
|
||||
Customer(user=skia, account_id="6568j", amount=0).save()
|
||||
p = ProductType(name="Bières bouteilles")
|
||||
p.save()
|
||||
Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7",
|
||||
special_selling_price="1.6", club=ae).save()
|
||||
Product(name="Chimay", code="CBLE", product_type=p, purchase_price="1.50", selling_price="1.7",
|
||||
special_selling_price="1.6", club=ae).save()
|
||||
barb = Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7",
|
||||
special_selling_price="1.6", club=ae)
|
||||
barb.save()
|
||||
cble = Product(name="Chimay Bleue", code="CBLE", product_type=p, purchase_price="1.50", selling_price="1.7",
|
||||
special_selling_price="1.6", club=ae)
|
||||
cble.save()
|
||||
Product(name="Corsendonk", code="CORS", product_type=p, purchase_price="1.50", selling_price="1.7",
|
||||
special_selling_price="1.6", club=ae).save()
|
||||
Product(name="Carolus", code="CARO", product_type=p, purchase_price="1.50", selling_price="1.7",
|
||||
special_selling_price="1.6", club=ae).save()
|
||||
mde = Counter(name="MDE", club=ae, type="BAR")
|
||||
mde.save()
|
||||
mde.products.add(barb)
|
||||
mde.products.add(cble)
|
||||
mde.save()
|
||||
|
||||
# Accounting test values:
|
||||
BankAccount(name="AE TG", club=ae).save()
|
||||
BankAccount(name="Carte AE", club=ae).save()
|
||||
ba = BankAccount(name="AE TI", club=ae)
|
||||
|
@ -7,3 +7,6 @@ admin.site.register(Customer)
|
||||
admin.site.register(ProductType)
|
||||
admin.site.register(Product)
|
||||
admin.site.register(Counter)
|
||||
admin.site.register(Refilling)
|
||||
admin.site.register(Selling)
|
||||
|
||||
|
42
counter/migrations/0002_refilling_selling.py
Normal file
42
counter/migrations/0002_refilling_selling.py
Normal file
@ -0,0 +1,42 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import accounting.models
|
||||
from django.conf import settings
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
('counter', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Refilling',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
('amount', accounting.models.CurrencyField(verbose_name='amount', decimal_places=2, max_digits=12)),
|
||||
('date', models.DateTimeField(verbose_name='date', auto_now=True)),
|
||||
('payment_method', models.CharField(verbose_name='payment method', max_length=255, choices=[('cheque', 'Chèque'), ('cash', 'Espèce')])),
|
||||
('counter', models.ForeignKey(to='counter.Counter', related_name='refillings')),
|
||||
('customer', models.ForeignKey(to='counter.Customer', related_name='refill_customers')),
|
||||
('operator', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='refill_operators')),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Selling',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
|
||||
('unit_price', accounting.models.CurrencyField(verbose_name='unit price', decimal_places=2, max_digits=12)),
|
||||
('quantity', models.IntegerField(verbose_name='quantity')),
|
||||
('date', models.DateTimeField(verbose_name='date', auto_now=True)),
|
||||
('counter', models.ForeignKey(to='counter.Counter', related_name='sellings')),
|
||||
('customer', models.ForeignKey(to='counter.Customer', related_name='customers')),
|
||||
('product', models.ForeignKey(to='counter.Product', related_name='sellings')),
|
||||
('seller', models.ForeignKey(to=settings.AUTH_USER_MODEL, related_name='sellers')),
|
||||
],
|
||||
),
|
||||
]
|
21
counter/migrations/0003_customer_amount.py
Normal file
21
counter/migrations/0003_customer_amount.py
Normal file
@ -0,0 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import accounting.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('counter', '0002_refilling_selling'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='customer',
|
||||
name='amount',
|
||||
field=accounting.models.CurrencyField(verbose_name='amount', default=0, decimal_places=2, max_digits=12),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
@ -18,6 +18,7 @@ class Customer(models.Model):
|
||||
"""
|
||||
user = models.OneToOneField(User, primary_key=True)
|
||||
account_id = models.CharField(_('account id'), max_length=10, unique=True)
|
||||
amount = CurrencyField(_('amount'))
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('customer')
|
||||
@ -108,9 +109,64 @@ class Counter(models.Model):
|
||||
Counter.barmen_session[counter_id]['users'] = set()
|
||||
return bl
|
||||
|
||||
def get_random_barman(counter_id): # TODO: improve this function
|
||||
bl = Counter.get_barmen_list(counter_id)
|
||||
return bl[0]
|
||||
|
||||
class Refilling(models.Model):
|
||||
"""
|
||||
Handle the refilling
|
||||
"""
|
||||
counter = models.ForeignKey(Counter, related_name="refillings", blank=False)
|
||||
amount = CurrencyField(_('amount'))
|
||||
operator = models.ForeignKey(User, related_name="refill_operators", blank=False)
|
||||
customer = models.ForeignKey(Customer, related_name="refill_customers", blank=False)
|
||||
date = models.DateTimeField(_('date'), auto_now=True)
|
||||
payment_method = models.CharField(_('payment method'), max_length=255,
|
||||
choices=settings.SITH_COUNTER_PAYMENT_METHOD)
|
||||
# TODO: add the bank if the payment is made by cheque
|
||||
|
||||
def __str__(self):
|
||||
return "Refilling: %f for %s" % (self.amount, self.customer.user.get_display_name())
|
||||
|
||||
# def get_absolute_url(self):
|
||||
# return reverse('counter:details', kwargs={'counter_id': self.id})
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.full_clean()
|
||||
self.customer.amount += self.quantity * self.unit_price
|
||||
self.customer.save()
|
||||
super(Selling, self).save(*args, **kwargs)
|
||||
|
||||
class Selling(models.Model):
|
||||
"""
|
||||
Handle the sellings
|
||||
"""
|
||||
product = models.ForeignKey(Product, related_name="sellings", blank=False)
|
||||
counter = models.ForeignKey(Counter, related_name="sellings", blank=False)
|
||||
unit_price = CurrencyField(_('unit price'))
|
||||
quantity = models.IntegerField(_('quantity'))
|
||||
seller = models.ForeignKey(User, related_name="sellers", blank=False)
|
||||
customer = models.ForeignKey(Customer, related_name="customers", blank=False)
|
||||
date = models.DateTimeField(_('date'), auto_now=True)
|
||||
|
||||
def __str__(self):
|
||||
return "Selling: %d x %s (%f) for %s" % (self.quantity, self.product.name,
|
||||
self.quantity*self.unit_price, self.customer.user.get_display_name())
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.full_clean()
|
||||
self.customer.amount -= self.quantity * self.unit_price
|
||||
self.customer.save()
|
||||
super(Selling, self).save(*args, **kwargs)
|
||||
|
||||
# def get_absolute_url(self):
|
||||
# return reverse('counter:details', kwargs={'counter_id': self.id})
|
||||
|
||||
|
||||
# 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,7 +12,7 @@ from django import forms
|
||||
|
||||
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
|
||||
from subscription.models import Subscriber
|
||||
from counter.models import Counter, Customer, Product
|
||||
from counter.models import Counter, Customer, Product, Selling, Refilling
|
||||
|
||||
class GetUserForm(forms.Form):
|
||||
"""
|
||||
@ -151,7 +151,11 @@ class CounterClick(DetailView):
|
||||
|
||||
def finish(self, request):
|
||||
""" Finish the click session, and validate the basket """
|
||||
# TODO: handle the basket
|
||||
for pid,qty in request.session['basket'].items():
|
||||
p = Product.objects.filter(pk=pid).first()
|
||||
s = Selling(product=p, counter=self.object, unit_price=p.selling_price,
|
||||
quantity=qty, seller=Counter.get_random_barman(self.object.id), customer=self.customer)
|
||||
s.save()
|
||||
kwargs = {'counter_id': self.object.id}
|
||||
del request.session['basket']
|
||||
return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args, kwargs=kwargs))
|
||||
|
@ -218,6 +218,11 @@ SITH_SUBSCRIPTION_PAYMENT_METHOD = [
|
||||
('other', 'Autre'),
|
||||
]
|
||||
|
||||
SITH_COUNTER_PAYMENT_METHOD = [
|
||||
('cheque', 'Chèque'),
|
||||
('cash', 'Espèce'),
|
||||
]
|
||||
|
||||
# Subscription durations are in semestres (should be settingized)
|
||||
SITH_SUBSCRIPTIONS = {
|
||||
'un-semestre': {
|
||||
|
Loading…
Reference in New Issue
Block a user