Skip to content

Commit

Permalink
Add Mileage account support (#57)
Browse files Browse the repository at this point in the history
* Add Mileage account

* Add Mileage account

* Add Mock to the test

* Add Mock to the test

* Add Mock to the test

* Add Mock to the test

* Add Mock to the test

* Add Mock to the test

* Code factor resolved

* Comments resolved
  • Loading branch information
ruuushhh authored Aug 28, 2023
1 parent c9f3eb3 commit 73be639
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
17 changes: 10 additions & 7 deletions apps/qbd/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def create_bill(
workspace_id=workspace_id
)

line_items = BillLineitem.create_bill_lineitems(expenses, bill, workspace_id)
line_items = BillLineitem.create_bill_lineitems(expenses, bill, workspace_id, export_settings)
return bill, line_items


Expand Down Expand Up @@ -260,7 +260,7 @@ class Meta:
db_table = 'bill_lineitems'

@staticmethod
def create_bill_lineitems(expenses: List[Expense], bill: Bill, workspace_id: int):
def create_bill_lineitems(expenses: List[Expense], bill: Bill, workspace_id: int, export_settings: ExportSettings):
"""
Create bill lineitem object
:param bill_lineitem: bill lineitem data
Expand All @@ -279,7 +279,8 @@ def create_bill_lineitems(expenses: List[Expense], bill: Bill, workspace_id: int
lineitem = BillLineitem.objects.create(
transaction_type='BILL',
date=expense.spent_at,
account=expense.category,
account=export_settings.mileage_account_name if expense.category == 'Mileage' and \
export_settings.mileage_account_name else expense.category,
name=project_name,
class_name=class_name,
amount=expense.amount,
Expand Down Expand Up @@ -371,6 +372,7 @@ def create_credit_card_purchase(
export_settings: ExportSettings,
accounting_export: AccountingExport,
workspace_id: int

):
"""
Create credit card purchase object
Expand Down Expand Up @@ -600,11 +602,11 @@ def create_journal(
)

lineitems = JournalLineitem.create_journal_lineitems(
expenses, journal, workspace_id
expenses, journal, workspace_id, export_settings, fund_source
)

return journal, lineitems


class JournalLineitem(models.Model):
"""
Expand Down Expand Up @@ -651,7 +653,7 @@ class Meta:

@staticmethod
def create_journal_lineitems(
expenses: List[Expense], journal: Journal, workspace_id: int
expenses: List[Expense], journal: Journal, workspace_id: int, export_settings: ExportSettings, fund_source: str
):
"""
Create Journal Lineitems
Expand All @@ -671,7 +673,8 @@ def create_journal_lineitems(
lineitem = JournalLineitem.objects.create(
transaction_type='GENERAL JOURNAL',
date=expense.spent_at,
account=expense.category,
account=export_settings.mileage_account_name if fund_source != 'CCC' and expense.category == 'Mileage' \
and export_settings.mileage_account_name else expense.category,
name=journal.name,
class_name=class_name,
amount=expense.amount * -1,
Expand Down
25 changes: 25 additions & 0 deletions apps/workspaces/migrations/0025_auto_20230823_1118.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 3.1.14 on 2023-08-23 11:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('workspaces', '0024_exportsettings_is_simplify_report_closure_enabled'),
]

operations = [
migrations.AddField(
model_name='exportsettings',
name='mileage_account_name',
field=models.CharField(help_text='Mileage account name', max_length=255, null=True),
),
migrations.AlterField(
model_name='exportsettings',
name='credit_card_expense_date',
field=models.CharField(choices=[('last_spent_at', 'last_spent_at'), ('spent_at', 'spent_at'), \
('posted_at', 'posted_at'), ('created_at', 'created_at')], max_length=255, \
null=True),
),
]
4 changes: 4 additions & 0 deletions apps/workspaces/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ class ExportSettings(models.Model):
max_length=255, help_text='Bank account name',
null=True
)
mileage_account_name = models.CharField(
max_length=255, help_text='Mileage account name',
null=True
)
reimbursable_expense_state = models.CharField(
max_length=255,
choices=REIMBURSABLE_EXPENSE_STATE_CHOICES,
Expand Down
8 changes: 7 additions & 1 deletion tests/test_fyle/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
from apps.fyle.helpers import post_request


def test_post_request():
def test_post_request(mocker):
class MockResponse:
def __init__(self, text, status_code):
self.text = text
self.status_code = status_code

url = 'https://api.instantwebtools.net/v1/airlines'

body = {
Expand All @@ -14,4 +19,5 @@ def test_post_request():
'website': 'www.srilankaairways.com',
'established': '1990'
}
mocker.patch('requests.post', return_value=(MockResponse("""{"data": "Airline Posted"}""", 200)))
post_request(url, body=json.dumps(body))

0 comments on commit 73be639

Please sign in to comment.