From ed5bcdbb4c3163864a43aba92d9ade01d7731026 Mon Sep 17 00:00:00 2001 From: ruuushhh <66899387+ruuushhh@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:46:14 +0530 Subject: [PATCH] Fix: journal entry amounts (#157) * Fix: journal entry amounts * fix tests * Fix test run --------- Co-authored-by: GitHub Actions --- .github/workflows/codecov.yml | 6 ++--- .github/workflows/tests.yml | 8 +++---- .../exports/journal_entry/models.py | 4 ++-- tests/test_business_central/test_models.py | 24 ++++++------------- 4 files changed, 16 insertions(+), 26 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index a4e7e98..282495f 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -15,9 +15,9 @@ jobs: - uses: actions/checkout@v2 - name: Bring up Services and Run Tests run: | - docker-compose -f docker-compose-pipeline.yml build - docker-compose -f docker-compose-pipeline.yml up -d - docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=70 + docker compose -f docker-compose-pipeline.yml build + docker compose -f docker-compose-pipeline.yml up -d + docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=70 echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV - name: Upload coverage reports to Codecov with GitHub Action diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e00b82b..61834d5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,12 +9,12 @@ jobs: runs-on: ubuntu-latest environment: CI Environment steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v2 - name: Bring up Services and Run Tests run: | - docker-compose -f docker-compose-pipeline.yml build - docker-compose -f docker-compose-pipeline.yml up -d - docker-compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=95 + docker compose -f docker-compose-pipeline.yml build + docker compose -f docker-compose-pipeline.yml up -d + docker compose -f docker-compose-pipeline.yml exec -T api pytest tests/ --cov --junit-xml=test-reports/report.xml --cov-report=xml --cov-fail-under=95 echo "STATUS=$(cat pytest-coverage.txt | grep 'Required test' | awk '{ print $1 }')" >> $GITHUB_ENV echo "FAILED=$(cat test-reports/report.xml | awk -F'=' '{print $5}' | awk -F' ' '{gsub(/"/, "", $1); print $1}')" >> $GITHUB_ENV - name: Upload coverage reports to Codecov with GitHub Action diff --git a/apps/business_central/exports/journal_entry/models.py b/apps/business_central/exports/journal_entry/models.py index 87b1664..3b8971a 100644 --- a/apps/business_central/exports/journal_entry/models.py +++ b/apps/business_central/exports/journal_entry/models.py @@ -54,7 +54,7 @@ def create_or_update_object(self, accounting_export: AccountingExport, _: Advanc journal_entry_object, _ = JournalEntry.objects.update_or_create( accounting_export= accounting_export, defaults={ - 'amount': sum([expense.amount for expense in expenses]) * -1, + 'amount': sum([expense.amount for expense in expenses]), 'document_number': document_number, 'accounts_payable_account_id': accounts_payable_account_id, 'account_id': account_id, @@ -119,7 +119,7 @@ def create_or_update_object(self, accounting_export: AccountingExport, advance_s journal_entry_id = journal_entry.id, expense_id=lineitem.id, defaults={ - 'amount': lineitem.amount, + 'amount': lineitem.amount * -1, 'account_id': account_id, 'account_type': account_type, 'document_number': document_number, diff --git a/tests/test_business_central/test_models.py b/tests/test_business_central/test_models.py index 20cb463..d913970 100644 --- a/tests/test_business_central/test_models.py +++ b/tests/test_business_central/test_models.py @@ -1,20 +1,10 @@ import pytest +from fyle_accounting_mappings.models import EmployeeMapping, ExpenseAttribute, Mapping, MappingSetting -from apps.business_central.models import ( - JournalEntry, - JournalEntryLineItems, - PurchaseInvoice, - PurchaseInvoiceLineitems -) -from fyle_accounting_mappings.models import ( - EmployeeMapping, - Mapping, - MappingSetting, - ExpenseAttribute -) -from apps.workspaces.models import AdvancedSetting, ExportSetting from apps.accounting_exports.models import AccountingExport, Expense from apps.business_central.exports.accounting_export import AccountingDataExporter +from apps.business_central.models import JournalEntry, JournalEntryLineItems, PurchaseInvoice, PurchaseInvoiceLineitems +from apps.workspaces.models import AdvancedSetting, ExportSetting def test_create_or_update_journal_entry_1( @@ -40,7 +30,7 @@ def test_create_or_update_journal_entry_1( journal_entry = JournalEntry.objects.first() assert journal_entry.accounting_export.workspace.id == 1 - assert journal_entry.amount == -50 + assert journal_entry.amount == 50 def test_create_or_update_journal_entry_2( @@ -76,7 +66,7 @@ def test_create_or_update_journal_entry_2( journal_entry = JournalEntry.objects.first() assert journal_entry.accounting_export.workspace.id == 1 - assert journal_entry.amount == -50 + assert journal_entry.amount == 50 def test_create_or_update_journal_entry_3( @@ -116,7 +106,7 @@ def test_create_or_update_journal_entry_3( journal_entry = JournalEntry.objects.first() assert journal_entry.accounting_export.workspace.id == 1 - assert journal_entry.amount == -50 + assert journal_entry.amount == 50 def test_create_or_update_journal_entry_line_items( @@ -151,7 +141,7 @@ def test_create_or_update_journal_entry_line_items( assert len(journal_line_items) == 1 assert journal_line_items[0].journal_entry.accounting_export.workspace.id == 1 - assert journal_line_items[0].journal_entry.amount == -50 + assert journal_line_items[0].journal_entry.amount == 50 def test_create_or_update_purchase_invoice(