Commit d60e14a3 authored by Sli's avatar Sli

Migration from old database

parent 7588cc8f
......@@ -39,7 +39,7 @@ from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operatio
from core.utils import resize_image
from club.models import Club, Membership
from subscription.models import Subscription
from counter.models import Customer, ProductType, Product, Counter
from counter.models import Customer, ProductType, Product, Counter, Selling
from com.models import Sith, Weekmail
from election.models import Election, Role, Candidature, ElectionList
from forum.models import Forum, ForumTopic
......@@ -485,6 +485,9 @@ Welcome to the wiki page!
start=s.subscription_start)
s.save()
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()
# Add barman to counter
c = Counter.objects.get(id=2)
c.sellers.add(User.objects.get(pk=krophil.pk))
......
......@@ -37,14 +37,18 @@
<h3>{% trans %}User account{% endtrans %}</h3>
<p>{% trans %}Amount: {% endtrans %}{{ customer.amount }}</p>
<div id="drop">
{% if customer.refillings.exists() %}
{% if customer.buyings.exists() %}
{% set bought = customer.buyings.exists() %}
{% set refilled = customer.refillings.exists() %}
{% if bought or refilled %}
{% if bought %}
<h5>{% trans %}Account buyings{% endtrans %}</h5>
{{ monthly(buyings_month) }}
{% endif %}
{% if refilled %}
<h5>{% trans %}Refillings{% endtrans %}</h5>
{{ monthly(refilling_month) }}
{% endif %}
{% endif %}
{% if customer.user.invoices.exists() %}
<h5>{% trans %}Eboutic invoices{% endtrans %}</h5>
{{ monthly(invoices_month) }}
......
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _
from django.db import migrations, models
from django.conf import settings
from core.models import User
from counter.models import Customer, Product, Selling, Counter
def balance_ecocups(apps, schema_editor):
for customer in Customer.objects.all():
for selling in customer.buyings.filter(product__id__in=[settings.SITH_RECORD_PRODUCT, settings.SITH_UNRECORD_PRODUCT]).all():
if selling.product.id == settings.SITH_RECORD_PRODUCT:
customer.recorded_products -= selling.quantity
elif selling.product.id == settings.SITH_UNRECORD_PRODUCT:
customer.recorded_products += selling.quantity
if customer.recorded_products > settings.SITH_RECORD_LIMIT:
qt = customer.recorded_products - settings.SITH_RECORD_LIMIT
cons = Product.objects.get(id=settings.SITH_RECORD_PRODUCT)
Selling(label=_("Record regularization"), product=cons, unit_price=cons.selling_price,
club=cons.club, counter=Counter.objects.filter(name='Foyer').first(),
quantity=qt, seller=User.objects.get(id=0), customer=customer).save()
customer.recorded_products -= qt
customer.save()
class Migration(migrations.Migration):
......@@ -16,4 +38,5 @@ class Migration(migrations.Migration):
name='recorded_products',
field=models.IntegerField(verbose_name='recorded items', default=0),
),
migrations.RunPython(balance_ecocups),
]
This diff is collapsed.
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