Skip to content

Commit

Permalink
Feat: Adding new Journal Entry changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Nov 20, 2024
1 parent 109e6d5 commit dad251d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
83 changes: 42 additions & 41 deletions apps/business_central/exports/journal_entry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,24 @@ def create_or_update_object(self, accounting_export: AccountingExport, _: Advanc
:param accounting_export: expense group
:return: purchase invoices object
"""
expenses = accounting_export.expenses.all()
expense = accounting_export.expenses.first()

accounts_payable_account_id = export_settings.default_bank_account_id

document_number = accounting_export.description['claim_number'] if accounting_export.description and accounting_export.description.get('claim_number') else accounting_export.description['expense_number']
advance_setting = AdvancedSetting.objects.get(workspace_id=accounting_export.workspace_id)

comment = "Consolidated Credit Entry For Report/Expense {}".format(document_number)
document_number = accounting_export.description['expense_number'] if accounting_export.description and accounting_export.description.get('expense_number') else None

comment = self.get_expense_comment(accounting_export.workspace_id, expense, expense.category, advance_setting)

invoice_date = self.get_invoice_date(accounting_export=accounting_export)

account_type, account_id = self.get_account_id_type(accounting_export=accounting_export, export_settings=export_settings)
account_type, account_id = self.get_account_id_type(accounting_export=accounting_export, export_settings=export_settings, merchant=expense.vendor)

journal_entry_object, _ = JournalEntry.objects.update_or_create(
accounting_export= accounting_export,
defaults={
'amount': sum([expense.amount for expense in expenses]),
'amount': expense.amount,
'document_number': document_number,
'accounts_payable_account_id': accounts_payable_account_id,
'account_id': account_id,
Expand Down Expand Up @@ -98,45 +100,44 @@ def create_or_update_object(self, accounting_export: AccountingExport, advance_s
:param accounting_export: expense group
:return: purchase invoices object
"""
expenses = accounting_export.expenses.all()
lineitem = accounting_export.expenses.first()
journal_entry = JournalEntry.objects.get(accounting_export=accounting_export)

journal_entry_lineitems = []

for lineitem in expenses:
category = lineitem.category if (lineitem.category == lineitem.sub_category or lineitem.sub_category == None) else '{0} / {1}'.format(lineitem.category, lineitem.sub_category)

account = CategoryMapping.objects.filter(
source_category__value=category,
workspace_id=accounting_export.workspace_id
).first()

comment = self.get_expense_comment(accounting_export.workspace_id, lineitem, lineitem.category, advance_setting)

invoice_date = self.get_invoice_date(accounting_export=accounting_export)

account_type, account_id = self.get_account_id_type(accounting_export=accounting_export, export_settings=export_settings, merchant=lineitem.vendor)

document_number = accounting_export.description['claim_number'] if accounting_export.description and accounting_export.description.get('claim_number') else accounting_export.description['expense_number']

dimensions = self.get_dimension_object(accounting_export, lineitem)

journal_entry_lineitems_object, _ = JournalEntryLineItems.objects.update_or_create(
journal_entry_id = journal_entry.id,
expense_id=lineitem.id,
defaults={
'amount': lineitem.amount * -1,
'account_id': account_id,
'account_type': account_type,
'document_number': document_number,
'accounts_payable_account_id': account.destination_account.destination_id,
'comment': comment,
'workspace_id': accounting_export.workspace_id,
'invoice_date': invoice_date,
'description': lineitem.purpose if lineitem.purpose else None,
'dimensions': dimensions
}
)
journal_entry_lineitems.append(journal_entry_lineitems_object)
category = lineitem.category if (lineitem.category == lineitem.sub_category or lineitem.sub_category == None) else '{0} / {1}'.format(lineitem.category, lineitem.sub_category)

account = CategoryMapping.objects.filter(
source_category__value=category,
workspace_id=accounting_export.workspace_id
).first()

comment = self.get_expense_comment(accounting_export.workspace_id, lineitem, lineitem.category, advance_setting)

invoice_date = self.get_invoice_date(accounting_export=accounting_export)

account_type, account_id = self.get_account_id_type(accounting_export=accounting_export, export_settings=export_settings, merchant=lineitem.vendor)

document_number = accounting_export.description['expense_number'] if accounting_export.description and accounting_export.description.get('expense_number') else None

dimensions = self.get_dimension_object(accounting_export, lineitem)

journal_entry_lineitems_object, _ = JournalEntryLineItems.objects.update_or_create(
journal_entry_id = journal_entry.id,
expense_id=lineitem.id,
defaults={
'amount': lineitem.amount * -1,
'account_id': account_id,
'account_type': account_type,
'document_number': document_number,
'accounts_payable_account_id': account.destination_account.destination_id,
'comment': comment,
'workspace_id': accounting_export.workspace_id,
'invoice_date': invoice_date,
'description': lineitem.purpose if lineitem.purpose else None,
'dimensions': dimensions
}
)
journal_entry_lineitems.append(journal_entry_lineitems_object)

return journal_entry_lineitems
12 changes: 10 additions & 2 deletions apps/business_central/exports/journal_entry/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from apps.business_central.utils import BusinessCentralConnector
from apps.workspaces.models import BusinessCentralCredentials

from fyle_accounting_mappings.models import DestinationAttribute

logger = logging.getLogger(__name__)
logger.level = logging.INFO

Expand Down Expand Up @@ -42,6 +44,12 @@ def __construct_journal_entry(self, body: JournalEntry, lineitems: List[JournalE
batch_journal_entry_payload = []
dimensions = []

account_attribute_type = DestinationAttribute.objects.filter(workspace_id=body.workspace_id, destination_id=body.accounts_payable_account_id).first()

balance_account_type = 'G/L Account'
if account_attribute_type and account_attribute_type.attribute_type == 'BANK_ACCOUNT':
balance_account_type = 'Bank Account'

journal_entry_payload = {
'accountType': body.account_type,
'accountNumber': body.account_id,
Expand All @@ -50,7 +58,7 @@ def __construct_journal_entry(self, body: JournalEntry, lineitems: List[JournalE
'amount': body.amount,
'comment': body.comment,
'description': body.description,
'balanceAccountType': 'G/L Account',
'balanceAccountType': balance_account_type,
'balancingAccountNumber': body.accounts_payable_account_id

}
Expand All @@ -70,7 +78,7 @@ def __construct_journal_entry(self, body: JournalEntry, lineitems: List[JournalE
'amount': lineitem.amount,
'comment': lineitem.comment,
'description': lineitem.description if lineitem.description else '',
'balanceAccountType': 'G/L Account',
'balanceAccountType': balance_account_type,
'balancingAccountNumber': lineitem.accounts_payable_account_id
}

Expand Down

0 comments on commit dad251d

Please sign in to comment.