-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
travelperk credentials and Invoices models with migrations (#102)
- Loading branch information
1 parent
b895d43
commit 73ff29e
Showing
13 changed files
with
297 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
[run] | ||
omit = workato/*, test.py, tests/*, ./venv/*, get-pip.py, fyle/*, admin_settings/*, *forms.py, *apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py, *settings.py, *gunicorn*, | ||
omit = connectors/*, workato/*, test.py, tests/*, ./venv/*, get-pip.py, fyle/*, admin_settings/*, *forms.py, *apps.py,*manage.py,*__init__.py,*migrations*,*asgi*,*wsgi*,*admin.py,*urls.py, *settings.py, *gunicorn*, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class TravelperkConfig(AppConfig): | ||
name = 'travelperk' | ||
name = 'apps.travelperk' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import logging | ||
from django.conf import settings | ||
|
||
|
||
from apps.travelperk.models import TravelperkCredential, TravelPerk | ||
from connectors.travelperk import Travelperk | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class TravelperkConnector: | ||
""" | ||
Travelperk Connector Class | ||
""" | ||
|
||
def __init__(self, credentials_object: TravelperkCredential, org_id: int): | ||
|
||
client_id = settings.TRAVELPERK_CLIENT_ID | ||
client_secret = settings.TRAVELPERK_CLIENT_SECRET | ||
environment = settings.TRAVELPERK_ENVIRONMENT | ||
refresh_token = credentials_object.refresh_token | ||
|
||
self.connection = Travelperk(client_id, client_secret, refresh_token, environment) | ||
self.org_id = org_id | ||
|
||
credentials_object.refresh_token = self.connection.refresh_token | ||
credentials_object.save() | ||
|
||
|
||
def create_webhook(self, data: dict): | ||
""" | ||
Create Webhook in Travelperk | ||
:param data: Webhook Data | ||
:return: Webhook Data | ||
""" | ||
|
||
response = self.connection.webhooks.create(data) | ||
if response: | ||
TravelPerk.objects.update_or_create( | ||
org_id=self.org_id, | ||
defaults={ | ||
'webhook_id': response['id'], | ||
'webhook_enabled': response['enabled'] | ||
} | ||
) | ||
|
||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
apps/travelperk/migrations/0005_invoice_invoicelineitem_travelperkcredential.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Generated by Django 3.1.14 on 2023-12-17 06:11 | ||
|
||
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='Invoice', | ||
fields=[ | ||
('id', models.AutoField(help_text='Unique identifier for the invoice.', primary_key=True, serialize=False)), | ||
('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.CharField(help_text='ID of the profile associated with the invoice.', max_length=255)), | ||
('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')), | ||
], | ||
options={ | ||
'db_table': 'invoices', | ||
}, | ||
), | ||
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='InvoiceLineItem', | ||
fields=[ | ||
('id', models.AutoField(help_text='Unique identifier for the line item.', primary_key=True, serialize=False)), | ||
('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.IntegerField(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.CharField(help_text='ID of the trip associated with this line item.', max_length=255)), | ||
('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)), | ||
('invoice', models.ForeignKey(help_text='Invoice associated with this line item.', on_delete=django.db.models.deletion.CASCADE, related_name='line_items', to='travelperk.invoice')), | ||
], | ||
options={ | ||
'db_table': 'invoice_line_items', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Generated by Django 3.1.14 on 2023-12-14 19:27 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('travelperk', '0005_invoice_invoicelineitem_travelperkcredential'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='travelperk', | ||
name='webhook_enabled', | ||
field=models.BooleanField(help_text='If Webhook Is Enabled', null=True), | ||
), | ||
migrations.AddField( | ||
model_name='travelperk', | ||
name='webhook_subscription_id', | ||
field=models.CharField(help_text='Webhook Subscription Id', max_length=255, null=True), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.