Migrate invoices and lot of eboutic improvements

This commit is contained in:
Skia
2016-08-18 19:52:20 +02:00
parent 50c452c287
commit 05bd177a9d
19 changed files with 470 additions and 156 deletions

View 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', '0008_auto_20160818_0231'),
]
operations = [
migrations.AlterField(
model_name='refilling',
name='payment_method',
field=models.CharField(verbose_name='payment method', default='CASH', choices=[('CHECK', 'Check'), ('CASH', 'Cash'), ('EBOUTIC', 'Eboutic')], max_length=255),
),
]

View 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', '0009_auto_20160818_1709'),
]
operations = [
migrations.AlterField(
model_name='refilling',
name='payment_method',
field=models.CharField(default='CASH', max_length=255, verbose_name='payment method', choices=[('CHECK', 'Check'), ('CASH', 'Cash'), ('CARD', 'Credit card')]),
),
]

View File

@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
('counter', '0010_auto_20160818_1716'),
]
operations = [
migrations.AlterField(
model_name='selling',
name='club',
field=models.ForeignKey(related_name='sellings', null=True, on_delete=django.db.models.deletion.SET_NULL, to='club.Club'),
),
migrations.AlterField(
model_name='selling',
name='counter',
field=models.ForeignKey(related_name='sellings', null=True, on_delete=django.db.models.deletion.SET_NULL, to='counter.Counter'),
),
migrations.AlterField(
model_name='selling',
name='customer',
field=models.ForeignKey(related_name='buyings', null=True, on_delete=django.db.models.deletion.SET_NULL, to='counter.Customer'),
),
migrations.AlterField(
model_name='selling',
name='product',
field=models.ForeignKey(related_name='sellings', null=True, on_delete=django.db.models.deletion.SET_NULL, blank=True, to='counter.Product'),
),
migrations.AlterField(
model_name='selling',
name='seller',
field=models.ForeignKey(related_name='sellings_as_operator', null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL),
),
]

View 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', '0011_auto_20160818_1722'),
]
operations = [
migrations.AddField(
model_name='selling',
name='payment_method',
field=models.CharField(default='SITH_ACCOUNT', max_length=255, verbose_name='payment method', choices=[('SITH_ACCOUNT', 'Compte AE'), ('CARD', 'Credit card')]),
),
]

View 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_selling_payment_method'),
]
operations = [
migrations.AlterField(
model_name='selling',
name='payment_method',
field=models.CharField(max_length=255, default='SITH_ACCOUNT', verbose_name='payment method', choices=[('SITH_ACCOUNT', 'Sith account'), ('CARD', 'Credit card')]),
),
]

View File

@ -5,7 +5,8 @@ from django.conf import settings
from django.core.urlresolvers import reverse
from django.forms import ValidationError
from datetime import timedelta
from datetime import timedelta, datetime
from pytz import timezone
import random
import string
@ -206,7 +207,7 @@ class Refilling(models.Model):
amount = CurrencyField(_('amount'))
operator = models.ForeignKey(User, related_name="refillings_as_operator", blank=False)
customer = models.ForeignKey(Customer, related_name="refillings", blank=False)
date = models.DateTimeField(_('date'), auto_now=True)
date = models.DateTimeField(_('date'))
payment_method = models.CharField(_('payment method'), max_length=255,
choices=settings.SITH_COUNTER_PAYMENT_METHOD, default='CASH')
bank = models.CharField(_('bank'), max_length=255,
@ -223,6 +224,8 @@ class Refilling(models.Model):
# return reverse('counter:details', kwargs={'counter_id': self.id})
def save(self, *args, **kwargs):
if not self.date:
self.date = datetime.now().replace(tzinfo=timezone(settings.TIME_ZONE))
self.full_clean()
if not self.is_validated:
self.customer.amount += self.amount
@ -235,14 +238,16 @@ class Selling(models.Model):
Handle the sellings
"""
label = models.CharField(_("label"), max_length=64)
product = models.ForeignKey(Product, related_name="sellings", null=True, blank=True)
counter = models.ForeignKey(Counter, related_name="sellings", blank=False)
club = models.ForeignKey(Club, related_name="sellings", blank=False)
product = models.ForeignKey(Product, related_name="sellings", null=True, blank=True, on_delete=models.SET_NULL)
counter = models.ForeignKey(Counter, related_name="sellings", null=True, blank=False, on_delete=models.SET_NULL)
club = models.ForeignKey(Club, related_name="sellings", null=True, blank=False, on_delete=models.SET_NULL)
unit_price = CurrencyField(_('unit price'))
quantity = models.IntegerField(_('quantity'))
seller = models.ForeignKey(User, related_name="sellings_as_operator", blank=False)
customer = models.ForeignKey(Customer, related_name="buyings", blank=False)
date = models.DateTimeField(_('date'), auto_now=True)
seller = models.ForeignKey(User, related_name="sellings_as_operator", null=True, blank=False, on_delete=models.SET_NULL)
customer = models.ForeignKey(Customer, related_name="buyings", null=True, blank=False, on_delete=models.SET_NULL)
date = models.DateTimeField(_('date'))
payment_method = models.CharField(_('payment method'), max_length=255,
choices=[('SITH_ACCOUNT', _('Sith account')), ('CARD', _('Credit card'))], default='SITH_ACCOUNT')
is_validated = models.BooleanField(_('is validated'), default=False)
class Meta:
@ -253,6 +258,8 @@ class Selling(models.Model):
self.quantity*self.unit_price, self.customer.user.get_display_name())
def save(self, *args, **kwargs):
if not self.date:
self.date = datetime.now().replace(tzinfo=timezone(settings.TIME_ZONE))
self.full_clean()
if not self.is_validated:
self.customer.amount -= self.quantity * self.unit_price

View File

@ -44,7 +44,8 @@ class GetUserForm(forms.Form):
elif cleaned_data['id'] is not None:
cus = Customer.objects.filter(user=cleaned_data['id']).first()
sub = get_subscriber(cus.user) if cus is not None else None
if cus is None or sub is None or (date.today() - sub.subscriptions.last().subscription_end) > timedelta(days=90):
if (cus is None or sub is None or not sub.subscriptions.last() or
(date.today() - sub.subscriptions.last().subscription_end) > timedelta(days=90)):
raise forms.ValidationError(_("User not found"))
cleaned_data['user_id'] = cus.user.id
cleaned_data['user'] = cus.user