Commit 748e3ae3 authored by Sli's avatar Sli
Browse files

Refactor and migration corrections

parent 240b68f9
Pipeline #1121 passed with stage
in 4 minutes and 25 seconds
...@@ -486,7 +486,7 @@ Welcome to the wiki page! ...@@ -486,7 +486,7 @@ Welcome to the wiki page!
s.save() s.save()
Selling(label=dcons.name, product=dcons, counter=mde, unit_price=dcons.selling_price, club=main_club, Selling(label=dcons.name, product=dcons, counter=mde, unit_price=dcons.selling_price, club=main_club,
quantity=settings.SITH_RECORD_LIMIT + 3, seller=skia, customer=krophil.customer).save() quantity=settings.SITH_ECOCUP_LIMIT + 3, seller=skia, customer=krophil.customer).save()
# Add barman to counter # Add barman to counter
c = Counter.objects.get(id=2) c = Counter.objects.get(id=2)
......
...@@ -12,18 +12,18 @@ from counter.models import Customer, Product, Selling, Counter ...@@ -12,18 +12,18 @@ from counter.models import Customer, Product, Selling, Counter
def balance_ecocups(apps, schema_editor): def balance_ecocups(apps, schema_editor):
for customer in Customer.objects.all(): for customer in Customer.objects.all():
customer.recorded_products = 0 customer.recorded_products = 0
for selling in customer.buyings.filter(product__id__in=[settings.SITH_RECORD_PRODUCT, settings.SITH_UNRECORD_PRODUCT]).all(): for selling in customer.buyings.filter(product__id__in=[settings.SITH_ECOCUP_CONS, settings.SITH_ECOCUP_DECO]).all():
if selling.product.id == settings.SITH_RECORD_PRODUCT: if selling.product.is_record_product:
customer.recorded_products -= selling.quantity
elif selling.product.id == settings.SITH_UNRECORD_PRODUCT:
customer.recorded_products += selling.quantity customer.recorded_products += selling.quantity
if customer.recorded_products > settings.SITH_RECORD_LIMIT: elif selling.product.is_unrecord_product:
qt = customer.recorded_products - settings.SITH_RECORD_LIMIT customer.recorded_products -= selling.quantity
cons = Product.objects.get(id=settings.SITH_RECORD_PRODUCT) if customer.recorded_products < -settings.SITH_ECOCUP_LIMIT:
Selling(label=_("Record regularization"), product=cons, unit_price=cons.selling_price, qt = -(customer.recorded_products + settings.SITH_ECOCUP_LIMIT)
cons = Product.objects.get(id=settings.SITH_ECOCUP_CONS)
Selling(label=_("Ecocup regularization"), product=cons, unit_price=cons.selling_price,
club=cons.club, counter=Counter.objects.filter(name='Foyer').first(), club=cons.club, counter=Counter.objects.filter(name='Foyer').first(),
quantity=qt, seller=User.objects.get(id=0), customer=customer).save(allow_negative=True) quantity=qt, seller=User.objects.get(id=0), customer=customer).save(allow_negative=True)
customer.recorded_products -= qt customer.recorded_products += qt
customer.save() customer.save()
......
...@@ -63,10 +63,10 @@ class Customer(models.Model): ...@@ -63,10 +63,10 @@ class Customer(models.Model):
@property @property
def can_record(self): def can_record(self):
return self.recorded_products > -settings.SITH_RECORD_LIMIT return self.recorded_products > -settings.SITH_ECOCUP_LIMIT
def can_record_more(self, number): def can_record_more(self, number):
return self.recorded_products - number >= -settings.SITH_RECORD_LIMIT return self.recorded_products - number >= -settings.SITH_ECOCUP_LIMIT
@property @property
def can_buy(self): def can_buy(self):
...@@ -80,8 +80,8 @@ class Customer(models.Model): ...@@ -80,8 +80,8 @@ class Customer(models.Model):
letter = random.choice(string.ascii_lowercase) letter = random.choice(string.ascii_lowercase)
return number + letter return number + letter
def save(self, allow_negative=False, is_purchase=False, *args, **kwargs): def save(self, allow_negative=False, is_selling=False, *args, **kwargs):
if self.amount < 0 and (is_purchase and not allow_negative): if self.amount < 0 and (is_selling and not allow_negative):
raise ValidationError(_("Not enough money")) raise ValidationError(_("Not enough money"))
super(Customer, self).save(*args, **kwargs) super(Customer, self).save(*args, **kwargs)
...@@ -153,11 +153,11 @@ class Product(models.Model): ...@@ -153,11 +153,11 @@ class Product(models.Model):
@property @property
def is_record_product(self): def is_record_product(self):
return settings.SITH_RECORD_PRODUCT == self.id return settings.SITH_ECOCUP_CONS == self.id
@property @property
def is_unrecord_product(self): def is_unrecord_product(self):
return settings.SITH_UNRECORD_PRODUCT == self.id return settings.SITH_ECOCUP_DECO == self.id
def is_owned_by(self, user): def is_owned_by(self, user):
""" """
...@@ -398,7 +398,7 @@ class Selling(models.Model): ...@@ -398,7 +398,7 @@ class Selling(models.Model):
self.full_clean() self.full_clean()
if not self.is_validated: if not self.is_validated:
self.customer.amount -= self.quantity * self.unit_price self.customer.amount -= self.quantity * self.unit_price
self.customer.save(allow_negative=allow_negative, is_purchase=True) self.customer.save(allow_negative=allow_negative, is_selling=True)
self.is_validated = True self.is_validated = True
u = User.objects.filter(id=self.customer.user.id).first() u = User.objects.filter(id=self.customer.user.id).first()
if u.was_subscribed: if u.was_subscribed:
......
This diff is collapsed.
...@@ -397,11 +397,11 @@ SITH_COUNTER_BANK = [ ...@@ -397,11 +397,11 @@ SITH_COUNTER_BANK = [
('LA-POSTE', 'La Poste'), ('LA-POSTE', 'La Poste'),
] ]
SITH_RECORD_PRODUCT = 1152 SITH_ECOCUP_CONS = 1152
SITH_UNRECORD_PRODUCT = 1151 SITH_ECOCUP_DECO = 1151
SITH_RECORD_LIMIT = 3 SITH_ECOCUP_LIMIT = 3
# Defines pagination for cash summary # Defines pagination for cash summary
SITH_COUNTER_CASH_SUMMARY_LENGTH = 50 SITH_COUNTER_CASH_SUMMARY_LENGTH = 50
......
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