From 7588cc8f73afdb2621df23b30d7aa78a2c4ebe92 Mon Sep 17 00:00:00 2001 From: klmp200 Date: Thu, 27 Jul 2017 16:53:53 +0200 Subject: [PATCH] Hardcoding ecocup values --- counter/models.py | 10 ++-------- counter/views.py | 7 ++++--- sith/settings.py | 8 ++------ 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/counter/models.py b/counter/models.py index 1f318914..b9850e19 100644 --- a/counter/models.py +++ b/counter/models.py @@ -153,17 +153,11 @@ class Product(models.Model): @property def is_record_product(self): - for product in settings.SITH_RECORD_PRODUCT: - if product == self.id: - return True - return False + return settings.SITH_RECORD_PRODUCT == self.id @property def is_unrecord_product(self): - for product in settings.SITH_UNRECORD_PRODUCT: - if product == self.id: - return True - return False + return settings.SITH_UNRECORD_PRODUCT == self.id def is_owned_by(self, user): """ diff --git a/counter/views.py b/counter/views.py index 7b529f2c..9d4963f8 100644 --- a/counter/views.py +++ b/counter/views.py @@ -381,7 +381,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): if self.customer.amount < (total + round(q * float(price), 2)): # Check for enough money request.session['not_enough'] = True return False - if not self.is_record_product_ok(request, product): + if product.is_unrecord_product and 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: @@ -446,6 +446,9 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): """ Finish the click session, and validate the basket """ with transaction.atomic(): request.session['last_basket'] = [] + if self.sum_basket(request) > self.customer.amount: + raise DataError(_("You have not enough money to buy all the basket")) + for pid, infos in request.session['basket'].items(): # This duplicates code for DB optimization (prevent to load many times the same object) p = Product.objects.filter(pk=pid).first() @@ -453,8 +456,6 @@ class CounterClick(CounterTabsMixin, CanViewMixin, DetailView): uprice = p.special_selling_price else: uprice = p.selling_price - if uprice * infos['qty'] > self.customer.amount: - raise DataError(_("You have not enough money to buy all the basket")) request.session['last_basket'].append("%d x %s" % (infos['qty'] + infos['bonus_qty'], p.name)) s = Selling(label=p.name, product=p, club=p.club, counter=self.object, unit_price=uprice, quantity=infos['qty'], seller=self.operator, customer=self.customer) diff --git a/sith/settings.py b/sith/settings.py index 89d315f9..c0ce5334 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -397,13 +397,9 @@ SITH_COUNTER_BANK = [ ('LA-POSTE', 'La Poste'), ] -SITH_RECORD_PRODUCT = [ - 1152, -] +SITH_RECORD_PRODUCT = 1152 -SITH_UNRECORD_PRODUCT = [ - 1151, -] +SITH_UNRECORD_PRODUCT = 1151 SITH_RECORD_LIMIT = 3