Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Foreign Amount #639

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions apps/netsuite/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -1650,8 +1650,17 @@ def construct_expense_report_lineitems(
lines = []

for line in expense_report_lineitems:
expense = Expense.objects.get(pk=line.expense_id)
expense: Expense = Expense.objects.get(pk=line.expense_id)
netsuite_custom_segments = line.netsuite_custom_segments

if expense.foreign_amount:
if expense.amount == 0:
foreign_amount = 0
else:
foreign_amount = expense.foreign_amount
else:
foreign_amount = None

Comment on lines +1653 to +1663
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor conditional logic for clarity and efficiency.

The changes made to handle the foreign_amount are logical, but the implementation can be simplified using a ternary operator for better readability and efficiency, as suggested by static analysis.

Replace the if-else block with a ternary operator to simplify the assignment of foreign_amount:

-            if expense.foreign_amount:
-                if expense.amount == 0:
-                    foreign_amount = 0
-                else:
-                    foreign_amount = expense.foreign_amount
-            else:
-                foreign_amount = None
+            foreign_amount = 0 if expense.amount == 0 and expense.foreign_amount else expense.foreign_amount

Committable suggestion was skipped due to low confidence.

Tools
Ruff

1657-1660: Use ternary operator foreign_amount = 0 if expense.amount == 0 else expense.foreign_amount instead of if-else-block

Replace if-else-block with foreign_amount = 0 if expense.amount == 0 else expense.foreign_amount

(SIM108)

if attachment_links and expense.expense_id in attachment_links:
netsuite_custom_segments.append(
{
Expand Down Expand Up @@ -1734,7 +1743,7 @@ def construct_expense_report_lineitems(
'exchangeRate': None,
'expenseDate': line.transaction_date,
'expMediaItem': None,
'foreignAmount': expense.foreign_amount if expense.foreign_amount else None,
'foreignAmount': foreign_amount,
'grossAmt': line.amount,
'isBillable': line.billable,
'isNonReimbursable': None,
Expand Down
Loading