diff --git a/RIGS/importer.py b/RIGS/importer.py index 7a2f12c3..9d6f86da 100644 --- a/RIGS/importer.py +++ b/RIGS/importer.py @@ -72,9 +72,27 @@ def import_organisations(): print("Found: " + object.__unicode__()) +def import_vat_rates(): + cursor = setup_cursor() + if cursor is None: + return + sql = """SELECT `id`, `start_date`, `start_time`, `comment`, `rate` FROM `vat_rates`""" + cursor.execute(sql) + for row in cursor.fetchall(): + object, created = models.VatRate.objects.get_or_create(pk=row[0], start_at=row[1] + " " + row[2], + comment=row[3], rate=row[4]) + if created: + print("Created: " + object.__unicode__()) + with transaction.atomic(), reversion.create_revision(): + object.save() + else: + print("Found: " + object.__unicode__()) + + def main(): # import_people() - import_organisations() + # import_organisations() + import_vat_rates() if __name__ == "__main__": diff --git a/RIGS/migrations/0007_vatrate.py b/RIGS/migrations/0007_vatrate.py new file mode 100644 index 00000000..07d7e497 --- /dev/null +++ b/RIGS/migrations/0007_vatrate.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations +import RIGS.models + + +class Migration(migrations.Migration): + dependencies = [ + ('RIGS', '0006_auto_20141105_1553'), + ] + + operations = [ + migrations.CreateModel( + name='VatRate', + fields=[ + ('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)), + ('start_at', models.DateTimeField()), + ('rate', models.DecimalField(max_digits=6, decimal_places=6)), + ('comment', models.CharField(max_length=255)), + ], + options={ + }, + bases=(models.Model, RIGS.models.RevisionMixin), + ), + ] diff --git a/RIGS/models.py b/RIGS/models.py index 417d8a54..d86c8e07 100644 --- a/RIGS/models.py +++ b/RIGS/models.py @@ -59,4 +59,14 @@ class Organisation(models.Model, RevisionMixin): string = self.name if len(self.notes) > 0: string += "*" - return string \ No newline at end of file + return string + + +@reversion.register +class VatRate(models.Model, RevisionMixin): + start_at = models.DateTimeField() + rate = models.DecimalField(max_digits=6, decimal_places=6) + comment = models.CharField(max_length=255) + + def __unicode__(self): + return self.comment + " " + self.start_at + " @ " + self.rate \ No newline at end of file