Skip to content

Commit

Permalink
Add django-simple-history to keep track of Reimbursement changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cuducos committed May 28, 2017
1 parent 2491aea commit 95c6eeb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
71 changes: 71 additions & 0 deletions jarbas/core/migrations/0025_historicalreimbursement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.1 on 2017-05-28 21:55
from __future__ import unicode_literals

from django.conf import settings
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('core', '0024_add_available_in_latest_dataset_field_to_reimbursement'),
]

operations = [
migrations.CreateModel(
name='HistoricalReimbursement',
fields=[
('id', models.IntegerField(auto_created=True, blank=True, db_index=True, verbose_name='ID')),
('document_id', models.IntegerField(db_index=True, verbose_name='Document ID')),
('last_update', models.DateTimeField(blank=True, db_index=True, editable=False, verbose_name='Last update')),
('available_in_latest_dataset', models.BooleanField(default=True, verbose_name='Available in the latest dataset')),
('year', models.IntegerField(db_index=True, verbose_name='Year')),
('applicant_id', models.IntegerField(db_index=True, verbose_name='Applicant ID')),
('total_reimbursement_value', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, verbose_name='Total reimbusrsement value')),
('total_net_value', models.DecimalField(db_index=True, decimal_places=3, max_digits=10, verbose_name='Total net value')),
('reimbursement_numbers', models.CharField(max_length=140, verbose_name='Reimbursement numbers')),
('net_values', models.CharField(max_length=140, verbose_name='Net values')),
('congressperson_id', models.IntegerField(blank=True, db_index=True, null=True, verbose_name='Congressperson ID')),
('congressperson_name', models.CharField(blank=True, db_index=True, max_length=140, null=True, verbose_name='Congressperson name')),
('congressperson_document', models.IntegerField(blank=True, null=True, verbose_name='Congressperson document')),
('party', models.CharField(blank=True, db_index=True, max_length=7, null=True, verbose_name='Party')),
('state', models.CharField(blank=True, db_index=True, max_length=2, null=True, verbose_name='State')),
('term_id', models.IntegerField(blank=True, null=True, verbose_name='Term ID')),
('term', models.IntegerField(blank=True, null=True, verbose_name='Term')),
('subquota_id', models.IntegerField(db_index=True, verbose_name='Subquota ID')),
('subquota_description', models.CharField(max_length=140, verbose_name='Subquota descrition')),
('subquota_group_id', models.IntegerField(blank=True, null=True, verbose_name='Subquota group ID')),
('subquota_group_description', models.CharField(blank=True, max_length=140, null=True, verbose_name='Subquota group description')),
('supplier', models.CharField(max_length=140, verbose_name='Supplier')),
('cnpj_cpf', models.CharField(blank=True, db_index=True, max_length=14, null=True, verbose_name='CNPJ or CPF')),
('document_type', models.IntegerField(verbose_name='Document type')),
('document_number', models.CharField(blank=True, max_length=140, null=True, verbose_name='Document number')),
('document_value', models.DecimalField(decimal_places=3, max_digits=10, verbose_name='Document value')),
('issue_date', models.DateField(verbose_name='Issue date')),
('month', models.IntegerField(db_index=True, verbose_name='Month')),
('remark_value', models.DecimalField(blank=True, decimal_places=3, max_digits=10, null=True, verbose_name='Remark value')),
('installment', models.IntegerField(blank=True, null=True, verbose_name='Installment')),
('batch_number', models.IntegerField(verbose_name='Batch number')),
('reimbursement_values', models.CharField(blank=True, max_length=140, null=True, verbose_name='Reimbusrsement values')),
('passenger', models.CharField(blank=True, max_length=140, null=True, verbose_name='Passenger')),
('leg_of_the_trip', models.CharField(blank=True, max_length=140, null=True, verbose_name='Leg of the trip')),
('probability', models.DecimalField(blank=True, decimal_places=5, max_digits=6, null=True, verbose_name='Probability')),
('suspicions', django.contrib.postgres.fields.jsonb.JSONField(blank=True, null=True, verbose_name='Suspicions')),
('receipt_fetched', models.BooleanField(db_index=True, default=False, verbose_name='Was the receipt URL fetched?')),
('receipt_url', models.CharField(blank=True, max_length=140, null=True, verbose_name='Receipt URL')),
('history_id', models.AutoField(primary_key=True, serialize=False)),
('history_date', models.DateTimeField()),
('history_type', models.CharField(choices=[('+', 'Created'), ('~', 'Changed'), ('-', 'Deleted')], max_length=1)),
('history_user', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to=settings.AUTH_USER_MODEL)),
],
options={
'get_latest_by': 'history_date',
'verbose_name': 'historical reimbursement',
'ordering': ('-history_date', '-history_id'),
},
),
]
3 changes: 3 additions & 0 deletions jarbas/core/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.contrib.postgres.fields import JSONField
from django.db import models
from requests import head
from simple_history.models import HistoricalRecords

from jarbas.core.querysets import ReimbursementQuerySet

Expand Down Expand Up @@ -77,6 +78,8 @@ class Reimbursement(models.Model):
receipt_fetched = models.BooleanField('Was the receipt URL fetched?', default=False, db_index=True)
receipt_url = models.CharField('Receipt URL', max_length=140, blank=True, null=True)

history = HistoricalRecords()

objects = models.Manager.from_queryset(ReimbursementQuerySet)()

class Meta:
Expand Down
2 changes: 2 additions & 0 deletions jarbas/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'django.contrib.staticfiles',
'test_without_migrations',
'corsheaders',
'simple_history',
'rest_framework',
'jarbas.core',
'jarbas.api',
Expand All @@ -53,6 +54,7 @@
'django.middleware.cache.UpdateCacheMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
'corsheaders.middleware.CorsMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dj-database-url==0.4.2
django-assets==0.12
django-bulk-update==2.0.0
django-cors-middleware==1.3.1
django-simple-history==1.8.2
django-test-without-migrations==0.6
djangorestframework==3.6.3
freezegun==0.3.9
Expand Down

0 comments on commit 95c6eeb

Please sign in to comment.