From 36ab7d5c246b14d767d501c4af80a782055888ee Mon Sep 17 00:00:00 2001 From: Nilesh Pant <58652823+NileshPant1999@users.noreply.github.com> Date: Tue, 23 Jan 2024 22:51:32 +0530 Subject: [PATCH] add org id to invoice table (#150) --- .../migrations/0009_invoice_org_id.py | 21 +++++++++++++++++++ apps/travelperk/models.py | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 apps/travelperk/migrations/0009_invoice_org_id.py diff --git a/apps/travelperk/migrations/0009_invoice_org_id.py b/apps/travelperk/migrations/0009_invoice_org_id.py new file mode 100644 index 00000000..fc604c48 --- /dev/null +++ b/apps/travelperk/migrations/0009_invoice_org_id.py @@ -0,0 +1,21 @@ +# Generated by Django 3.1.14 on 2024-01-23 16:48 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('orgs', '0004_auto_20230627_1133'), + ('travelperk', '0008_auto_20240102_0517'), + ] + + operations = [ + migrations.AddField( + model_name='invoice', + name='org_id', + field=models.ForeignKey(default=1, help_text='Reference to Org table', on_delete=django.db.models.deletion.CASCADE, to='orgs.org'), + preserve_default=False, + ), + ] diff --git a/apps/travelperk/models.py b/apps/travelperk/models.py index 0a24064a..20f099d5 100644 --- a/apps/travelperk/models.py +++ b/apps/travelperk/models.py @@ -28,6 +28,7 @@ class Invoice(models.Model): billing_information = models.JSONField(help_text='Billing information associated with the invoice.') billing_period = models.CharField(max_length=20, help_text='Billing period type (e.g., instant).') currency = models.CharField(max_length=3, help_text='Currency code (e.g., GBP).') + org_id = models.ForeignKey(Org, on_delete=models.CASCADE, help_text='Reference to Org table') due_date = models.DateField(help_text='Due date for the invoice.') from_date = models.DateField(help_text='Start date for the billing period.') to_date = models.DateField(help_text='End date for the billing period.') @@ -50,11 +51,12 @@ class Invoice(models.Model): exported_to_fyle = models.BooleanField(default=False, help_text='If the invoice is exported to Fyle') + class Meta: db_table = 'invoices' @staticmethod - def create_or_update_invoices(invoice_data): + def create_or_update_invoices(invoice_data, org_id): """ Create or update invoice object """ @@ -62,6 +64,7 @@ def create_or_update_invoices(invoice_data): # Create or update Invoice object based on serial_number invoice_object, _ = Invoice.objects.update_or_create( serial_number=invoice_data['serial_number'], + org_id=org_id, defaults={ 'billing_information': invoice_data['billing_information'], 'billing_period': invoice_data['billing_period'],