Skip to content

Commit

Permalink
bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashutosh619-sudo committed Nov 20, 2024
1 parent 104338a commit 109e6d5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
32 changes: 17 additions & 15 deletions apps/business_central/exports/journal_entry/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ def __construct_journal_entry(self, body: JournalEntry, lineitems: List[JournalE
batch_journal_entry_payload.append(journal_entry_payload)

for lineitem in lineitems:
for dimension in lineitem.dimensions:
dimension['exported_module_id'] = lineitem.id

dimensions.extend(lineitem.dimensions)
journal_entry_lineitem_payload = {
'accountType': lineitem.account_type,
Expand Down Expand Up @@ -89,20 +92,17 @@ def post(self, accounting_export, item, lineitem):
# Post the journal entry to Business Central
response = business_central_connection.bulk_post_journal_lineitems(batch_journal_entry_payload, accounting_export)

try:
if dimensions:
dimension_set_line_payloads = self.construct_dimension_set_line_payload(dimensions, response['responses'])
logger.info('WORKSPACE_ID: {0}, ACCOUNTING_EXPORT_ID: {1}, DIMENSION_SET_LINE_PAYLOADS: {2}'.format(accounting_export.workspace_id, accounting_export.id, dimension_set_line_payloads))
dimension_line_responses = (
business_central_connection.post_dimension_lines(
dimension_set_line_payloads, "JOURNAL_ENTRY"
)

if dimensions:
dimension_set_line_payloads = self.construct_dimension_set_line_payload(dimensions, response['responses'])
logger.info('WORKSPACE_ID: {0}, ACCOUNTING_EXPORT_ID: {1}, DIMENSION_SET_LINE_PAYLOADS: {2}'.format(accounting_export.workspace_id, accounting_export.id, dimension_set_line_payloads))
dimension_line_responses = (
business_central_connection.post_dimension_lines(
dimension_set_line_payloads, "JOURNAL_ENTRY"
)
response["dimension_line_responses"] = dimension_line_responses
except Exception as exception:
lineitem.dimension_error_log = str(exception.response)
response['dimension_line_responses'] = str(exception.response)
lineitem.save()
)
response["dimension_line_responses"] = dimension_line_responses


expenses = accounting_export.expenses.all()

Expand Down Expand Up @@ -132,14 +132,16 @@ def construct_dimension_set_line_payload(self, dimensions: list, exported_respon
"code": dimension['code'],
"parentId": exported_response[0]['body']['id'],
"valueId": dimension['valueId'],
"valueCode": dimension['valueCode']
"valueCode": dimension['valueCode'],
"exported_module_id": dimension['exported_module_id']
},
{
"id": dimension['id'],
"code": dimension['code'],
"parentId": exported_response[1]['body']['id'],
"valueId": dimension['valueId'],
"valueCode": dimension['valueCode']
"valueCode": dimension['valueCode'],
"exported_module_id": dimension['exported_module_id']
}]

return dimension_payload
Expand Down
28 changes: 23 additions & 5 deletions apps/business_central/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import base64
import logging
from typing import Dict, List
from collections import defaultdict

from datetime import datetime
from django.utils import timezone

from dynamics.core.client import Dynamics
from fyle_accounting_mappings.models import DestinationAttribute

from apps.business_central.exports.journal_entry.models import JournalEntryLineItems
from apps.business_central.exports.purchase_invoice.models import PurchaseInvoiceLineitems
from apps.workspaces.models import BusinessCentralCredentials, ExportSetting, Workspace
from ms_business_central_api import settings

Expand Down Expand Up @@ -295,13 +299,27 @@ def post_dimension_lines(self, dimension_line_payloads: List[Dict], export_modul
"""
Post dimension line for purchase invoice line and Journal line item
"""
exception_response = []

for dimension_line_payload in dimension_line_payloads:
if export_module_type == 'JOURNAL_ENTRY':
response = self.connection.journal_line_items.post_journal_entry_dimensions(journal_line_item_id=dimension_line_payload['parentId'], data=dimension_line_payload)
else:
response = self.connection.purchase_invoice_line_items.post_purchase_invoice_dimensions(purchase_invoice_item_id=dimension_line_payload['parentId'], data=dimension_line_payload)
exported_module_id = dimension_line_payload['exported_module_id']
dimension_line_payload.pop('exported_module_id')
try:
if export_module_type == 'JOURNAL_ENTRY':
response = self.connection.journal_line_items.post_journal_entry_dimensions(journal_line_item_id=dimension_line_payload['parentId'], data=dimension_line_payload)
else:
response = self.connection.purchase_invoice_line_items.post_purchase_invoice_dimensions(purchase_invoice_item_id=dimension_line_payload['parentId'], data=dimension_line_payload)
except Exception as exception:
if export_module_type == 'JOURNAL_ENTRY':
lineitem = JournalEntryLineItems.objects.get(id=exported_module_id)
else:
lineitem = PurchaseInvoiceLineitems.objects.get(id=exported_module_id)

lineitem.dimension_error_log = str(exception.response)
lineitem.save()
exception_response.append(str(exception.response))

return response
return exception_response

def post_attachments(
self, ref_type: str, ref_id: str, attachments: List[Dict]
Expand Down

0 comments on commit 109e6d5

Please sign in to comment.