Skip to content

Commit

Permalink
travelperk models with migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
NileshPant1999 committed Dec 13, 2023
1 parent af0f366 commit cbd9b81
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 3 deletions.
2 changes: 1 addition & 1 deletion apps/travelperk/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


class TravelperkConfig(AppConfig):
name = 'travelperk'
name = 'apps.travelperk'
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Generated by Django 3.1.14 on 2023-12-13 18:51

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('orgs', '0004_auto_20230627_1133'),
('travelperk', '0004_travelperk_is_travel_perk_connected'),
]

operations = [
migrations.CreateModel(
name='InvoiceLineItem',
fields=[
('id', models.UUIDField(editable=False, help_text='Unique identifier for the line item.', primary_key=True, serialize=False, unique=True)),
('expense_date', models.DateField(help_text='Date of the expense for this line item.')),
('description', models.CharField(help_text='Description of the product or service.', max_length=255)),
('quantity', models.PositiveIntegerField(help_text='Quantity of the product or service.')),
('unit_price', models.DecimalField(decimal_places=2, help_text='Unit price of the product or service.', max_digits=10)),
('non_taxable_unit_price', models.DecimalField(decimal_places=2, help_text='Non-taxable unit price.', max_digits=10)),
('tax_percentage', models.DecimalField(decimal_places=2, help_text='Tax percentage applied.', max_digits=5)),
('tax_amount', models.DecimalField(decimal_places=2, help_text='Total tax amount for this line item.', max_digits=10)),
('tax_regime', models.CharField(help_text='Tax regime for this line item.', max_length=20)),
('total_amount', models.DecimalField(decimal_places=2, help_text='Total amount including taxes.', max_digits=10)),
('trip_id', models.PositiveIntegerField(help_text='ID of the trip associated with this line item.')),
('trip_name', models.CharField(help_text='Name of the trip associated with this line item.', max_length=255)),
('service', models.CharField(help_text='Type of service (e.g., PREMIUM).', max_length=50)),
('booker_name', models.CharField(help_text='Name of the person who booked the service.', max_length=100)),
('booker_email', models.EmailField(help_text='Email address of the person who booked the service.', max_length=254)),
('cost_center', models.CharField(help_text='Cost center associated with this line item.', max_length=20)),
('credit_card_last_4_digits', models.CharField(help_text='Last 4 digits of the credit card used for payment.', max_length=4)),
],
options={
'db_table': 'invoice_line_items',
},
),
migrations.CreateModel(
name='TravelperkCredential',
fields=[
('id', models.AutoField(help_text='Unique Id to indentify a Credentials', primary_key=True, serialize=False)),
('refresh_token', models.CharField(help_text='Travelperk Refresh Token', max_length=255, null=True)),
('created_at', models.DateTimeField(auto_now_add=True, help_text='Created at datetime')),
('updated_at', models.DateTimeField(auto_now=True, help_text='Updated at datetime')),
('org', models.OneToOneField(help_text='Reference to Org table', on_delete=django.db.models.deletion.PROTECT, to='orgs.org')),
],
options={
'db_table': 'travelperk_credentials',
},
),
migrations.CreateModel(
name='Invoice',
fields=[
('id', models.UUIDField(editable=False, help_text='Unique identifier for the invoice.', primary_key=True, serialize=False, unique=True)),
('billing_information', models.JSONField(help_text='Billing information associated with the invoice.')),
('billing_period', models.CharField(help_text='Billing period type (e.g., instant).', max_length=20)),
('currency', models.CharField(help_text='Currency code (e.g., GBP).', max_length=3)),
('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.')),
('issuing_date', models.DateField(help_text='Date when the invoice was issued.')),
('mode', models.CharField(choices=[('reseller', 'Reseller'), ('direct', 'Direct')], help_text='Mode of the invoice, indicating whether it is a reseller or direct invoice.', max_length=20)),
('pdf', models.URLField(help_text='URL to the PDF version of the invoice.')),
('profile_id', models.UUIDField(help_text='ID of the profile associated with the invoice.')),
('profile_name', models.CharField(help_text='Name of the profile associated with the invoice.', max_length=255)),
('reference', models.CharField(help_text='Reference information for the invoice (e.g., Trip #9876543).', max_length=50)),
('serial_number', models.CharField(help_text='Serial number of the invoice.', max_length=20)),
('status', models.CharField(help_text='Status of the invoice (e.g., paid).', max_length=20)),
('taxes_summary', models.JSONField(help_text='Summary of taxes applied to the invoice.')),
('total', models.DecimalField(decimal_places=2, help_text='Total amount of the invoice.', max_digits=10)),
('travelperk_bank_account', models.CharField(blank=True, help_text='TravelPerk bank account information if available.', max_length=50, null=True)),
('exported_to_fyle', models.BooleanField(default=False, help_text='If the invoice is exported to Fyle')),
('lines', models.ManyToManyField(help_text='Line items associated with the invoice.', to='travelperk.InvoiceLineItem')),
],
options={
'db_table': 'invoices',
},
),
]
90 changes: 89 additions & 1 deletion apps/travelperk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,94 @@
from apps.orgs.models import Org

# Create your models here.

class TravelperkCredential(models.Model):
"""
Travelperk Credential Model
"""

id = models.AutoField(primary_key=True, help_text='Unique Id to indentify a Credentials')
org = models.OneToOneField(Org, on_delete=models.PROTECT, help_text='Reference to Org table')
refresh_token = models.CharField(max_length=255, null=True, help_text='Travelperk Refresh Token')
created_at = models.DateTimeField(auto_now_add=True, help_text='Created at datetime')
updated_at = models.DateTimeField(auto_now=True, help_text='Updated at datetime')

class Meta:
db_table = 'travelperk_credentials'


from django.db import models

class InvoiceLineItem(models.Model):
"""
Travelperk Invoice Line Item Model
"""

id = models.UUIDField(primary_key=True, editable=False, unique=True, help_text='Unique identifier for the line item.')
expense_date = models.DateField(help_text='Date of the expense for this line item.')
description = models.CharField(max_length=255, help_text='Description of the product or service.')
quantity = models.PositiveIntegerField(help_text='Quantity of the product or service.')
unit_price = models.DecimalField(max_digits=10, decimal_places=2, help_text='Unit price of the product or service.')
non_taxable_unit_price = models.DecimalField(max_digits=10, decimal_places=2, help_text='Non-taxable unit price.')
tax_percentage = models.DecimalField(max_digits=5, decimal_places=2, help_text='Tax percentage applied.')
tax_amount = models.DecimalField(max_digits=10, decimal_places=2, help_text='Total tax amount for this line item.')
tax_regime = models.CharField(max_length=20, help_text='Tax regime for this line item.')
total_amount = models.DecimalField(max_digits=10, decimal_places=2, help_text='Total amount including taxes.')

# Metadata
trip_id = models.PositiveIntegerField(help_text='ID of the trip associated with this line item.')
trip_name = models.CharField(max_length=255, help_text='Name of the trip associated with this line item.')
service = models.CharField(max_length=50, help_text='Type of service (e.g., PREMIUM).')

# Booker
booker_name = models.CharField(max_length=100, help_text='Name of the person who booked the service.')
booker_email = models.EmailField(help_text='Email address of the person who booked the service.')

# Cost Center
cost_center = models.CharField(max_length=20, help_text='Cost center associated with this line item.')

# Other Fields
credit_card_last_4_digits = models.CharField(max_length=4, help_text='Last 4 digits of the credit card used for payment.')

class Meta:
db_table = 'invoice_line_items'


class Invoice(models.Model):
"""
Travelperk Invoice Model
"""

id = models.UUIDField(primary_key=True, editable=False, unique=True, help_text='Unique identifier for the invoice.')
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).')
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.')
issuing_date = models.DateField(help_text='Date when the invoice was issued.')
lines = models.ManyToManyField(InvoiceLineItem, help_text='Line items associated with the invoice.')
mode = models.CharField(
max_length=20,
choices=[('reseller', 'Reseller'), ('direct', 'Direct')],
help_text='Mode of the invoice, indicating whether it is a reseller or direct invoice.'
)
pdf = models.URLField(help_text='URL to the PDF version of the invoice.')
profile_id = models.UUIDField(help_text='ID of the profile associated with the invoice.')
profile_name = models.CharField(max_length=255, help_text='Name of the profile associated with the invoice.')
reference = models.CharField(max_length=50, help_text='Reference information for the invoice (e.g., Trip #9876543).')
serial_number = models.CharField(max_length=20, help_text='Serial number of the invoice.')
status = models.CharField(max_length=20, help_text='Status of the invoice (e.g., paid).')
taxes_summary = models.JSONField(help_text='Summary of taxes applied to the invoice.')
total = models.DecimalField(max_digits=10, decimal_places=2, help_text='Total amount of the invoice.')
travelperk_bank_account = models.CharField(max_length=50, null=True, blank=True, help_text='TravelPerk bank account information if available.')

exported_to_fyle = models.BooleanField(default=False, help_text='If the invoice is exported to Fyle')

class Meta:
db_table = 'invoices'


class TravelPerk(models.Model):
"""
Travelperk Model
Expand Down Expand Up @@ -34,4 +122,4 @@ class TravelPerkConfiguration(models.Model):
is_recipe_enabled = models.BooleanField(help_text='recipe status', null=True)

class Meta:
db_table = 'travelperk_configurations'
db_table = 'travelperk_configurations'
2 changes: 1 addition & 1 deletion apps/travelperk/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
from django.conf import settings
import traceback
from rest_framework import generics
from rest_framework.response import Response
from rest_framework.views import status
Expand All @@ -16,7 +17,6 @@

from .helpers import get_refresh_token_using_auth_code


logger = logging.getLogger(__name__)
logger.level = logging.INFO

Expand Down

0 comments on commit cbd9b81

Please sign in to comment.