mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 14:13:21 +00:00
Add limit for ecocup recording
This commit is contained in:
parent
2058d58db6
commit
40927fa13d
@ -340,6 +340,8 @@ Welcome to the wiki page!
|
|||||||
c.save()
|
c.save()
|
||||||
r = ProductType(name="Rechargements")
|
r = ProductType(name="Rechargements")
|
||||||
r.save()
|
r.save()
|
||||||
|
verre = ProductType(name="Verre")
|
||||||
|
verre.save()
|
||||||
cotis = Product(name="Cotis 1 semestre", code="1SCOTIZ", product_type=c, purchase_price="15", selling_price="15",
|
cotis = Product(name="Cotis 1 semestre", code="1SCOTIZ", product_type=c, purchase_price="15", selling_price="15",
|
||||||
special_selling_price="15", club=main_club)
|
special_selling_price="15", club=main_club)
|
||||||
cotis.save()
|
cotis.save()
|
||||||
@ -355,6 +357,14 @@ Welcome to the wiki page!
|
|||||||
cble = Product(name="Chimay Bleue", code="CBLE", product_type=p, purchase_price="1.50", selling_price="1.7",
|
cble = Product(name="Chimay Bleue", code="CBLE", product_type=p, purchase_price="1.50", selling_price="1.7",
|
||||||
special_selling_price="1.6", club=main_club)
|
special_selling_price="1.6", club=main_club)
|
||||||
cble.save()
|
cble.save()
|
||||||
|
cons = Product(name="Consigne Eco-cup", code="CONS", product_type=verre, purchase_price="1", selling_price="1",
|
||||||
|
special_selling_price="1", club=main_club)
|
||||||
|
cons.id = 1152
|
||||||
|
cons.save()
|
||||||
|
dcons = Product(name="Déconsigne Eco-cup", code="DECO", product_type=verre, purchase_price="-1", selling_price="-1",
|
||||||
|
special_selling_price="-1", club=main_club)
|
||||||
|
dcons.id = 1151
|
||||||
|
dcons.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=main_club).save()
|
special_selling_price="1.6", club=main_club).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",
|
||||||
@ -362,6 +372,8 @@ Welcome to the wiki page!
|
|||||||
mde = Counter.objects.filter(name="MDE").first()
|
mde = Counter.objects.filter(name="MDE").first()
|
||||||
mde.products.add(barb)
|
mde.products.add(barb)
|
||||||
mde.products.add(cble)
|
mde.products.add(cble)
|
||||||
|
mde.products.add(cons)
|
||||||
|
mde.products.add(dcons)
|
||||||
mde.sellers.add(skia)
|
mde.sellers.add(skia)
|
||||||
mde.save()
|
mde.save()
|
||||||
|
|
||||||
|
19
counter/migrations/0013_customer_recorded_products.py
Normal file
19
counter/migrations/0013_customer_recorded_products.py
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('counter', '0012_auto_20170515_2202'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='customer',
|
||||||
|
name='recorded_products',
|
||||||
|
field=models.IntegerField(verbose_name='recorded items', default=0),
|
||||||
|
),
|
||||||
|
]
|
@ -51,6 +51,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'))
|
amount = CurrencyField(_('amount'))
|
||||||
|
recorded_products = models.IntegerField(_('recorded product'), default=0)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('customer')
|
verbose_name = _('customer')
|
||||||
@ -60,6 +61,13 @@ class Customer(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s - %s" % (self.user.username, self.account_id)
|
return "%s - %s" % (self.user.username, self.account_id)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def can_record(self):
|
||||||
|
return self.recorded_products > -settings.SITH_RECORD_LIMIT
|
||||||
|
|
||||||
|
def can_record_more(self, number):
|
||||||
|
return self.recorded_products - number >= -settings.SITH_RECORD_LIMIT
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def can_buy(self):
|
def can_buy(self):
|
||||||
return (self.user.subscriptions.last() and
|
return (self.user.subscriptions.last() and
|
||||||
@ -143,6 +151,20 @@ class Product(models.Model):
|
|||||||
class Meta:
|
class Meta:
|
||||||
verbose_name = _('product')
|
verbose_name = _('product')
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_record_product(self):
|
||||||
|
for product in settings.SITH_RECORD_PRODUCT:
|
||||||
|
if product == self.id:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_unrecord_product(self):
|
||||||
|
for product in settings.SITH_UNRECORD_PRODUCT:
|
||||||
|
if product == self.id:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def is_owned_by(self, user):
|
def is_owned_by(self, user):
|
||||||
"""
|
"""
|
||||||
Method to see if that object can be edited by the given user
|
Method to see if that object can be edited by the given user
|
||||||
|
@ -330,6 +330,28 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
|
|||||||
except:
|
except:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
def compute_record_product(self, request, product=None):
|
||||||
|
recorded = 0
|
||||||
|
basket = request.session['basket']
|
||||||
|
|
||||||
|
if product:
|
||||||
|
if product.is_record_product:
|
||||||
|
recorded -= 1
|
||||||
|
elif product.is_unrecord_product:
|
||||||
|
recorded += 1
|
||||||
|
|
||||||
|
for p in basket:
|
||||||
|
bproduct = self.get_product(str(p))
|
||||||
|
if bproduct.is_record_product:
|
||||||
|
recorded -= basket[p]['qty']
|
||||||
|
elif bproduct.is_unrecord_product:
|
||||||
|
recorded += basket[p]['qty']
|
||||||
|
return recorded
|
||||||
|
|
||||||
|
def is_record_product_ok(self, request, product):
|
||||||
|
return self.customer.can_record_more(
|
||||||
|
self.compute_record_product(request, product))
|
||||||
|
|
||||||
def add_product(self, request, q=1, p=None):
|
def add_product(self, request, q=1, p=None):
|
||||||
"""
|
"""
|
||||||
Add a product to the basket
|
Add a product to the basket
|
||||||
@ -359,6 +381,9 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
|
|||||||
if self.customer.amount < (total + round(q * float(price), 2)): # Check for enough money
|
if self.customer.amount < (total + round(q * float(price), 2)): # Check for enough money
|
||||||
request.session['not_enough'] = True
|
request.session['not_enough'] = True
|
||||||
return False
|
return False
|
||||||
|
if not self.is_record_product_ok(request, product):
|
||||||
|
request.session['not_allowed'] = True
|
||||||
|
return False
|
||||||
if product.limit_age >= 18 and not self.customer.user.date_of_birth:
|
if product.limit_age >= 18 and not self.customer.user.date_of_birth:
|
||||||
request.session['no_age'] = True
|
request.session['no_age'] = True
|
||||||
return False
|
return False
|
||||||
@ -438,6 +463,8 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView):
|
|||||||
s = Selling(label=p.name + " (Plateau)", product=p, club=p.club, counter=self.object, unit_price=0,
|
s = Selling(label=p.name + " (Plateau)", product=p, club=p.club, counter=self.object, unit_price=0,
|
||||||
quantity=infos['bonus_qty'], seller=self.operator, customer=self.customer)
|
quantity=infos['bonus_qty'], seller=self.operator, customer=self.customer)
|
||||||
s.save()
|
s.save()
|
||||||
|
self.customer.recorded_products -= self.compute_record_product(request)
|
||||||
|
self.customer.save()
|
||||||
request.session['last_customer'] = self.customer.user.get_display_name()
|
request.session['last_customer'] = self.customer.user.get_display_name()
|
||||||
request.session['last_total'] = "%0.2f" % self.sum_basket(request)
|
request.session['last_total'] = "%0.2f" % self.sum_basket(request)
|
||||||
request.session['new_customer_amount'] = str(self.customer.amount)
|
request.session['new_customer_amount'] = str(self.customer.amount)
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -397,6 +397,16 @@ SITH_COUNTER_BANK = [
|
|||||||
('LA-POSTE', 'La Poste'),
|
('LA-POSTE', 'La Poste'),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
SITH_RECORD_PRODUCT = [
|
||||||
|
1152,
|
||||||
|
]
|
||||||
|
|
||||||
|
SITH_UNRECORD_PRODUCT = [
|
||||||
|
1151,
|
||||||
|
]
|
||||||
|
|
||||||
|
SITH_RECORD_LIMIT = 3
|
||||||
|
|
||||||
# Defines pagination for cash summary
|
# Defines pagination for cash summary
|
||||||
SITH_COUNTER_CASH_SUMMARY_LENGTH = 50
|
SITH_COUNTER_CASH_SUMMARY_LENGTH = 50
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user