Skip to content

Commit

Permalink
feat: add exchage rate support for JE (#700)
Browse files Browse the repository at this point in the history
* feat: add exchage rate support for JE

* fix tests

---------

Co-authored-by: GitHub Actions <[email protected]>
  • Loading branch information
ruuushhh and GitHub Actions committed Nov 27, 2024
1 parent 58b5445 commit 0afa02e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
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),
),
]
3 changes: 2 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 Down Expand Up @@ -736,6 +736,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
12 changes: 7 additions & 5 deletions tests/sql_fixtures/reset_db_fixtures/reset_db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- PostgreSQL database dump
--

-- Dumped from database version 15.9 (Debian 15.9-1.pgdg120+1)
-- Dumped from database version 15.7 (Debian 15.7-1.pgdg120+1)
-- Dumped by pg_dump version 15.8 (Debian 15.8-1.pgdg120+1)

SET statement_timeout = 0;
Expand Down Expand Up @@ -1337,7 +1337,8 @@ CREATE TABLE public.journal_entries (
private_note text NOT NULL,
created_at timestamp with time zone NOT NULL,
updated_at timestamp with time zone NOT NULL,
expense_group_id integer NOT NULL
expense_group_id integer NOT NULL,
exchange_rate double precision
);


Expand Down Expand Up @@ -4068,9 +4069,11 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin;
187 workspaces 0046_workspacegeneralsettings_import_code_fields 2024-08-02 07:52:56.494868+00
188 fyle_accounting_mappings 0026_destinationattribute_code 2024-08-02 08:35:52.537882+00
189 quickbooks_online 0015_add_bill_number 2024-08-29 14:29:50.588003+00
190 quickbooks_online 0015_bill_is_retired 2024-09-03 15:08:15.085332+00
190 quickbooks_online 0016_bill_is_retired 2024-09-03 15:08:15.085332+00
191 fyle 0038_expensegroup_export_url 2024-08-03 14:24:57.600169+00
192 fyle 0039_expense_is_posted_at_null 2024-11-14 11:09:52.364321+00
193 fyle 0040_expense_masked_corporate_card_number 2024-11-19 11:22:38.855388+00
194 quickbooks_online 0017_journalentry_exchange_rate 2024-11-27 15:08:15.085332+00
\.


Expand Down Expand Up @@ -33484,7 +33487,7 @@ COPY public.import_logs (id, attribute_type, status, error_log, total_batches_co
-- Data for Name: journal_entries; Type: TABLE DATA; Schema: public; Owner: postgres
--

COPY public.journal_entries (id, transaction_date, currency, private_note, created_at, updated_at, expense_group_id) FROM stdin;
COPY public.journal_entries (id, transaction_date, currency, private_note, created_at, updated_at, expense_group_id, exchange_rate) FROM stdin;
\.


Expand Down Expand Up @@ -35904,4 +35907,3 @@ ALTER TABLE ONLY public.workspaces_user
--
-- PostgreSQL database dump complete
--

0 comments on commit 0afa02e

Please sign in to comment.