get application
This commit is contained in:
parent
97f12875cb
commit
8471621bce
5 changed files with 40 additions and 23 deletions
32
apps/transactions/migrations/0002_auto_20191213_1423.py
Normal file
32
apps/transactions/migrations/0002_auto_20191213_1423.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
# Generated by Django 3.0 on 2019-12-13 14:23
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('transactions', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='transaction',
|
||||||
|
name='application_id',
|
||||||
|
field=models.IntegerField(blank=True, null=True, verbose_name='application ID'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='transaction',
|
||||||
|
name='code',
|
||||||
|
field=models.IntegerField(db_index=True, unique=True, verbose_name='code'),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='transaction',
|
||||||
|
name='detail_id',
|
||||||
|
field=models.IntegerField(blank=True, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterUniqueTogether(
|
||||||
|
name='transaction',
|
||||||
|
unique_together={('application_id', 'detail_id')},
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,18 +0,0 @@
|
||||||
# Generated by Django 3.0 on 2019-12-13 13:52
|
|
||||||
|
|
||||||
from django.db import migrations, models
|
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
|
||||||
|
|
||||||
dependencies = [
|
|
||||||
('transactions', '0001_initial'),
|
|
||||||
]
|
|
||||||
|
|
||||||
operations = [
|
|
||||||
migrations.AddField(
|
|
||||||
model_name='transaction',
|
|
||||||
name='application_id',
|
|
||||||
field=models.IntegerField(blank=True, null=True, verbose_name='application ID'),
|
|
||||||
),
|
|
||||||
]
|
|
||||||
|
|
@ -52,7 +52,7 @@ class Transaction(models.Model):
|
||||||
(5, 'done', 'done'),
|
(5, 'done', 'done'),
|
||||||
)
|
)
|
||||||
|
|
||||||
code = models.IntegerField(_('code'), blank=False) # unique random number
|
code = models.IntegerField(_('code'), blank=False, unique=True, db_index=True) # unique random number
|
||||||
amount = models.IntegerField(_('amount'), blank=False)
|
amount = models.IntegerField(_('amount'), blank=False)
|
||||||
delay = models.IntegerField(default=0, blank=True) # number of days for delayed payments
|
delay = models.IntegerField(default=0, blank=True) # number of days for delayed payments
|
||||||
payer = models.ForeignKey(User, on_delete=models.PROTECT, related_name='payments', blank=True, null=True)
|
payer = models.ForeignKey(User, on_delete=models.PROTECT, related_name='payments', blank=True, null=True)
|
||||||
|
|
@ -61,10 +61,13 @@ class Transaction(models.Model):
|
||||||
create = models.DateTimeField(_('create'), blank=True, null=True, auto_now=True)
|
create = models.DateTimeField(_('create'), blank=True, null=True, auto_now=True)
|
||||||
last_update = models.DateTimeField(_('last update'), blank=True, null=True, auto_now=True)
|
last_update = models.DateTimeField(_('last update'), blank=True, null=True, auto_now=True)
|
||||||
application_id = models.IntegerField("application ID", blank=True, null=True)
|
application_id = models.IntegerField("application ID", blank=True, null=True)
|
||||||
detail_id = models.IntegerField(null=True, blank=True, unique=True) # or better detail url or res number
|
detail_id = models.IntegerField(null=True, blank=True) # or better detail url or res number
|
||||||
|
|
||||||
objects = TransactionManager()
|
objects = TransactionManager()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
unique_together = ('application_id', 'detail_id',)
|
||||||
|
|
||||||
def set_code(self):
|
def set_code(self):
|
||||||
# TODO: set infinite algorithm
|
# TODO: set infinite algorithm
|
||||||
for code in random.sample(range(10000, 100000), 90000):
|
for code in random.sample(range(10000, 100000), 90000):
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ from .models import Transaction
|
||||||
class TransactionSerializer(serializers.ModelSerializer):
|
class TransactionSerializer(serializers.ModelSerializer):
|
||||||
payer = PublicUserSerializer(required=False)
|
payer = PublicUserSerializer(required=False)
|
||||||
payee = PublicUserSerializer(required=False, read_only=True)
|
payee = PublicUserSerializer(required=False, read_only=True)
|
||||||
application_id = serializers.IntegerField(required=False, read_only=True)
|
# application_id = serializers.IntegerField(required=False, read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Transaction
|
model = Transaction
|
||||||
|
|
@ -24,7 +24,7 @@ class TransactionSerializer(serializers.ModelSerializer):
|
||||||
'application_id'
|
'application_id'
|
||||||
)
|
)
|
||||||
|
|
||||||
read_only_fields = ['last_update', 'code', 'state', 'create', 'detail_id']
|
read_only_fields = ['last_update', 'code', 'state', 'create', 'detail_id', 'application_id']
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class TransactionList(generics.ListCreateAPIView):
|
||||||
application_id = None
|
application_id = None
|
||||||
|
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
serializer.save(payee=user, application_id=application_id)
|
serializer.save(payee=user, application_id=application_id )
|
||||||
|
|
||||||
|
|
||||||
class TransactionDetail(generics.RetrieveAPIView):
|
class TransactionDetail(generics.RetrieveAPIView):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue