Commit 6c48b7c7 authored by Skia's avatar Skia
Browse files

Add Selling and Refilling classes

parent 356a2d26
Pipeline #30 passed with stage
in 1 minute and 10 seconds
...@@ -8,7 +8,7 @@ from core.models import Group, User, Page, PageRev ...@@ -8,7 +8,7 @@ from core.models import Group, User, Page, PageRev
from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType
from club.models import Club, Membership from club.models import Club, Membership
from subscription.models import Subscription, Subscriber from subscription.models import Subscription, Subscriber
from counter.models import Customer, ProductType, Product from counter.models import Customer, ProductType, Product, Counter
class Command(BaseCommand): class Command(BaseCommand):
help = "Populate a new instance of the Sith AE" 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. ...@@ -138,18 +138,27 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
address="Terre Du Milieu", parent=ae) address="Terre Du Milieu", parent=ae)
troll.save() troll.save()
# Accounting test values: # Counters
Customer(user=skia, account_id="6568j").save() Customer(user=skia, account_id="6568j", amount=0).save()
p = ProductType(name="Bières bouteilles") p = ProductType(name="Bières bouteilles")
p.save() p.save()
Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7", barb = Product(name="Barbar", code="BARB", product_type=p, purchase_price="1.50", selling_price="1.7",
special_selling_price="1.6", club=ae).save() special_selling_price="1.6", club=ae)
Product(name="Chimay", code="CBLE", product_type=p, purchase_price="1.50", selling_price="1.7", barb.save()
special_selling_price="1.6", club=ae).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", Product(name="Corsendonk", code="CORS", product_type=p, purchase_price="1.50", selling_price="1.7",
special_selling_price="1.6", club=ae).save() special_selling_price="1.6", club=ae).save()
Product(name="Carolus", code="CARO", product_type=p, purchase_price="1.50", selling_price="1.7", Product(name="Carolus", code="CARO", product_type=p, purchase_price="1.50", selling_price="1.7",
special_selling_price="1.6", club=ae).save() 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="AE TG", club=ae).save()
BankAccount(name="Carte AE", club=ae).save() BankAccount(name="Carte AE", club=ae).save()
ba = BankAccount(name="AE TI", club=ae) ba = BankAccount(name="AE TI", club=ae)
......
...@@ -7,3 +7,6 @@ admin.site.register(Customer) ...@@ -7,3 +7,6 @@ admin.site.register(Customer)
admin.site.register(ProductType) admin.site.register(ProductType)
admin.site.register(Product) admin.site.register(Product)
admin.site.register(Counter) admin.site.register(Counter)
admin.site.register(Refilling)
admin.site.register(Selling)
# -*- 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')),
],
),
]
# -*- 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): ...@@ -18,6 +18,7 @@ class Customer(models.Model):
""" """
user = models.OneToOneField(User, primary_key=True) user = models.OneToOneField(User, primary_key=True)
account_id = models.CharField(_('account id'), max_length=10, unique=True) account_id = models.CharField(_('account id'), max_length=10, unique=True)
amount = CurrencyField(_('amount'))
class Meta: class Meta:
verbose_name = _('customer') verbose_name = _('customer')
...@@ -108,9 +109,64 @@ class Counter(models.Model): ...@@ -108,9 +109,64 @@ class Counter(models.Model):
Counter.barmen_session[counter_id]['users'] = set() Counter.barmen_session[counter_id]['users'] = set()
return bl 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: # TODO:
# une classe Vente # une classe Vente
# foreign key vers comptoir, vendeur, client, produit, mais stocker le prix du produit, pour gerer les maj de prix # foreign key vers comptoir, vendeur, client, produit, mais stocker le prix du produit, pour gerer les maj de prix
# une classe Rechargement # une classe Rechargement
# foreign key vers comptoir, vendeur, client, plus montant # foreign key vers comptoir, vendeur, client, plus montant
...@@ -12,7 +12,7 @@ from django import forms ...@@ -12,7 +12,7 @@ from django import forms
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from subscription.models import Subscriber 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): class GetUserForm(forms.Form):
""" """
...@@ -151,7 +151,11 @@ class CounterClick(DetailView): ...@@ -151,7 +151,11 @@ class CounterClick(DetailView):
def finish(self, request): def finish(self, request):
""" Finish the click session, and validate the basket """ """ 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} kwargs = {'counter_id': self.object.id}
del request.session['basket'] del request.session['basket']
return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args, kwargs=kwargs)) return HttpResponseRedirect(reverse_lazy('counter:details', args=self.args, kwargs=kwargs))
......
...@@ -218,6 +218,11 @@ SITH_SUBSCRIPTION_PAYMENT_METHOD = [ ...@@ -218,6 +218,11 @@ SITH_SUBSCRIPTION_PAYMENT_METHOD = [
('other', 'Autre'), ('other', 'Autre'),
] ]
SITH_COUNTER_PAYMENT_METHOD = [
('cheque', 'Chèque'),
('cash', 'Espèce'),
]
# Subscription durations are in semestres (should be settingized) # Subscription durations are in semestres (should be settingized)
SITH_SUBSCRIPTIONS = { SITH_SUBSCRIPTIONS = {
'un-semestre': { 'un-semestre': {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment