Skip to content

Commit

Permalink
Merge branch 'master' into internal-apis
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwin1111 authored Nov 27, 2024
2 parents 0fa5eb2 + 999ccde commit 5ca70db
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 96 deletions.
18 changes: 18 additions & 0 deletions apps/fyle/migrations/0040_expense_masked_corporate_card_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-11-19 11:21

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('fyle', '0039_expense_is_posted_at_null'),
]

operations = [
migrations.AddField(
model_name='expense',
name='masked_corporate_card_number',
field=models.CharField(help_text='Masked Corporate Card Number', max_length=255, null=True),
),
]
2 changes: 2 additions & 0 deletions apps/fyle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ class Expense(models.Model):
custom_properties = JSONField(null=True)
previous_export_state = models.CharField(max_length=255, help_text='Previous export state', null=True)
accounting_export_summary = JSONField(default=dict)
masked_corporate_card_number = models.CharField(max_length=255, help_text='Masked Corporate Card Number', null=True)
paid_on_qbo = models.BooleanField(help_text='Expense Payment status on QBO', default=False)
paid_on_fyle = models.BooleanField(help_text='Expense Payment status on Fyle', default=False)
payment_number = models.CharField(max_length=55, help_text='Expense payment number', null=True)
Expand Down Expand Up @@ -167,6 +168,7 @@ def create_expense_objects(expenses: List[Dict], workspace_id: int, skip_update:
'purpose': expense['purpose'],
'report_id': expense['report_id'],
'corporate_card_id': expense['corporate_card_id'],
'masked_corporate_card_number': expense['masked_corporate_card_number'],
'bank_transaction_id': expense['bank_transaction_id'],
'file_ids': expense['file_ids'],
'spent_at': expense['spent_at'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.14 on 2024-11-27 05:19

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('quickbooks_online', '0016_bill_is_retired'),
]

operations = [
migrations.AddField(
model_name='journalentry',
name='exchange_rate',
field=models.FloatField(help_text='Exchange rate', null=True),
),
]
5 changes: 4 additions & 1 deletion apps/quickbooks_online/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

from django.conf import settings
from django.db import models
from fyle_accounting_mappings.models import DestinationAttribute, EmployeeMapping, ExpenseAttribute, Mapping, MappingSetting

from apps.fyle.models import Expense, ExpenseGroup, ExpenseGroupSettings
from apps.mappings.models import GeneralMapping
from apps.workspaces.models import Workspace, WorkspaceGeneralSettings
from fyle_accounting_mappings.models import DestinationAttribute, EmployeeMapping, ExpenseAttribute, Mapping, MappingSetting


def get_transaction_date(expense_group: ExpenseGroup) -> str:
Expand All @@ -34,6 +34,8 @@ def get_expense_purpose(workspace_id, lineitem, category, workspace_general_sett

details = {
'employee_email': lineitem.employee_email,
'employee_name': lineitem.employee_name,
'card_number': '{0}'.format(lineitem.masked_corporate_card_number) if lineitem.masked_corporate_card_number else '',
'merchant': '{0}'.format(lineitem.vendor) if lineitem.vendor else '',
'category': '{0}'.format(category) if lineitem.category else '',
'purpose': '{0}'.format(lineitem.purpose) if lineitem.purpose else '',
Expand Down Expand Up @@ -736,6 +738,7 @@ class JournalEntry(models.Model):
transaction_date = models.DateField(help_text='JournalEntry transaction date')
currency = models.CharField(max_length=255, help_text='JournalEntry Currency')
private_note = models.TextField(help_text='JournalEntry Description')
exchange_rate = models.FloatField(help_text='Exchange rate', null=True)
created_at = models.DateTimeField(auto_now_add=True, help_text='Created at')
updated_at = models.DateTimeField(auto_now=True, help_text='Updated at')

Expand Down
9 changes: 9 additions & 0 deletions apps/quickbooks_online/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,6 +1224,8 @@ def __construct_journal_entry(self, journal_entry: JournalEntry, journal_entry_l
"""
general_mappings = GeneralMapping.objects.filter(workspace_id=self.workspace_id).first()
general_settings = WorkspaceGeneralSettings.objects.filter(workspace_id=self.workspace_id).first()
qbo_home_currency = QBOCredential.objects.get(workspace_id=self.workspace_id).currency
fyle_home_currency = journal_entry.currency

tax_rate_refs = []

Expand All @@ -1235,6 +1237,13 @@ def __construct_journal_entry(self, journal_entry: JournalEntry, journal_entry_l

journal_entry_payload = {'TxnDate': journal_entry.transaction_date, 'PrivateNote': journal_entry.private_note, 'Line': lines, 'CurrencyRef': {"value": journal_entry.currency}, 'TxnTaxDetail': {'TaxLine': []}}

if general_settings.is_multi_currency_allowed and fyle_home_currency != qbo_home_currency and qbo_home_currency:
exchange_rate = self.connection.exchange_rates.get_by_source(source_currency_code=fyle_home_currency)
journal_entry_payload['ExchangeRate'] = exchange_rate['Rate'] if "Rate" in exchange_rate else 1

journal_entry.exchange_rate = journal_entry_payload['ExchangeRate']
journal_entry.save(update_fields=['exchange_rate'])

if general_settings.import_tax_codes:
journal_entry_payload.update({'GlobalTaxCalculation': 'TaxInclusive'})

Expand Down
Loading

0 comments on commit 5ca70db

Please sign in to comment.