Skip to content

Commit

Permalink
add org id to invoice table (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 authored Jan 23, 2024
1 parent 74e2a2c commit 36ab7d5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
21 changes: 21 additions & 0 deletions apps/travelperk/migrations/0009_invoice_org_id.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
5 changes: 4 additions & 1 deletion apps/travelperk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand All @@ -50,18 +51,20 @@ 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
"""

# 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'],
Expand Down

0 comments on commit 36ab7d5

Please sign in to comment.