Skip to content
Snippets Groups Projects
Commit df5c970d authored by Piotr Gawron's avatar Piotr Gawron
Browse files

voucher data structure

parent 113fedfc
No related branches found
No related tags found
1 merge request!113Resolve "voucher functionality"
# -*- coding: utf-8 -*-
# Generated by Django 1.10.7 on 2017-12-08 13:12
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('web', '0090_vouchertype_vouchertypeprice'),
]
operations = [
migrations.AlterField(
model_name='vouchertypeprice',
name='voucher_type',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='prices', to='web.VoucherType'),
),
]
...@@ -81,3 +81,12 @@ COUNTRY_AFGHANISTAN_ID = 2 ...@@ -81,3 +81,12 @@ COUNTRY_AFGHANISTAN_ID = 2
# id of the singleton Study, # id of the singleton Study,
# TODO remove after allowing many studies per Smasch instance # TODO remove after allowing many studies per Smasch instance
GLOBAL_STUDY_ID = 1 GLOBAL_STUDY_ID = 1
VOUCHER_STATUS_NEW = "NEW"
VOUCHER_STATUS_USED = "USED"
VOUCHER_STATUS_EXPIRED = "EXPIRED"
VOUCHER_STATUS_CHOICES = (
(VOUCHER_STATUS_NEW, 'New'),
(VOUCHER_STATUS_USED, 'Used'),
(VOUCHER_STATUS_EXPIRED, 'Expired'),
)
# coding=utf-8
import datetime
from time import timezone
from django.db import models
from models import VoucherType, StudySubject, Worker
from models.constants import VOUCHER_STATUS_CHOICES, VOUCHER_STATUS_NEW
class Voucher(models.Model):
class Meta:
app_label = 'web'
number = models.CharField(
max_length=10,
verbose_name='Number',
blank=False,
null=False,
unique=True
)
issue_date = models.DateField(verbose_name='Issue date', null=False)
expiry_date = models.DateField(verbose_name='Expiry date', null=False)
use_date = models.DateField(verbose_name='Use date')
voucher_type = models.ForeignKey(
VoucherType,
on_delete=models.CASCADE,
null=False,
)
study_subject = models.ForeignKey(
StudySubject,
on_delete=models.CASCADE,
null=False,
editable=False
)
status = models.CharField(max_length=20, choices=VOUCHER_STATUS_CHOICES.items(),
verbose_name='Status',
default=VOUCHER_STATUS_NEW
)
feedback = models.TextField(max_length=2000,
blank=True,
verbose_name='Feedback'
)
usage_partner = models.ForeignKey(
Worker,
on_delete=models.CASCADE,
)
def save(self, *args, **kwargs):
if not self.id:
self.issue_date = timezone.now()
self.expiry_date = self.issue_date + datetime.timedelta(days=92)
return super(Voucher, self).save(*args, **kwargs)
def __str__(self):
return "%s - %s %s" % (self.number, self.study_subject.subject.first_name, self.study_subject.subject.last_name)
def __unicode__(self):
return "%s - %s %s" % (self.number, self.study_subject.subject.first_name, self.study_subject.subject.last_name)
...@@ -53,6 +53,6 @@ class VoucherTypePriceViewTests(LoggedInTestCase): ...@@ -53,6 +53,6 @@ class VoucherTypePriceViewTests(LoggedInTestCase):
url = reverse('web.views.voucher_type_price_edit', url = reverse('web.views.voucher_type_price_edit',
kwargs={'pk': voucher_type_price.id, 'voucher_type_id': voucher_type_price.voucher_type.id}) kwargs={'pk': voucher_type_price.id, 'voucher_type_id': voucher_type_price.voucher_type.id})
response = self.client.post(url, data=form_data) self.client.post(url, data=form_data)
self.assertEqual(90.50, VoucherTypePrice.objects.get(id=voucher_type_price.id).price) self.assertEqual(90.50, VoucherTypePrice.objects.get(id=voucher_type_price.id).price)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment