Skip to content

Commit

Permalink
Feat: Added api for bank account, dimensions and dimension_set lines (#…
Browse files Browse the repository at this point in the history
…23)

* Feat: Added api for bank account, dimensions and dimension_set lines

* comment resolved

* added count for bank account

* added count api for dimension values

* comment resolved

* bump up version
  • Loading branch information
Ashutosh619-sudo authored Nov 15, 2024
1 parent efa614e commit a4898f6
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 5 deletions.
6 changes: 5 additions & 1 deletion dynamics/apis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from .attachments import Attachments
from .employees import Employees
from .locations import Locations
from .dimensions import Dimensions
from .bank_accounts import BankAccounts

__all__ = [
'Companies',
Expand All @@ -19,5 +21,7 @@
'PurchaseInvoiceLineItems',
'Attachments',
'Employees',
'Locations'
'Locations',
'Dimensions',
'BankAccounts',
]
26 changes: 26 additions & 0 deletions dynamics/apis/bank_accounts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from .api_base import ApiBase


class BankAccounts(ApiBase):
"""Class for Bank Accounts APIs."""

GET_BANK_ACCOUNT = '/bankAccounts'
COUNT_BANK_ACCOUNT = '/bankAccounts/$count'

def get_all(self, **kwargs):
"""
Get all bank accounts
:return: returns all bank accounts
"""
return self._get_request({
**kwargs
}, BankAccounts.GET_BANK_ACCOUNT)['value']

def count(self, **kwargs):
"""
Get counts of locations
:return: Count in Int
"""
return self._get_request_for_count({
**kwargs
}, BankAccounts.COUNT_BANK_ACCOUNT)['value']
51 changes: 51 additions & 0 deletions dynamics/apis/dimensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from .api_base import ApiBase


class Dimensions(ApiBase):
"""Class for Locations APIs."""

GET_DIMENSION = '/dimensions'
GET_DIMENSION_VALUES = '/dimensions({0})/dimensionValues'
COUNT_DIMENSIONS = '/dimensions/$count'
COUNT_DIMENSIONS_VALUES = '/dimensions({0})/dimensionValues/$count'

def get_all_dimensions(self, **kwargs):
"""
Get all dimensions
:return: returns all companies
"""
return self._get_request({
**kwargs
}, Dimensions.GET_DIMENSION)['value']

def get_all_dimension_values(self, dimension_id:str, **kwargs):
"""
Get all dimension_values
Parameters:
dimension_name (str): Dimension name.
:return: returns all companies
"""
return self._get_request({
**kwargs
}, (Dimensions.GET_DIMENSION_VALUES).format(dimension_id))['value']

def count(self, **kwargs):
"""
Get counts of dimensions
:return: Count in Int
"""
return self._get_request_for_count({
**kwargs
}, Dimensions.COUNT_DIMENSIONS)['value']

def count_dimension_values(self, destination_id:str, **kwargs):
"""
Get counts of dimensions values with the given destination_id
:return: Count in Int
"""

return self._get_request_for_count({
**kwargs
}, (Dimensions.COUNT_DIMENSIONS_VALUES).format(destination_id))['value']
14 changes: 14 additions & 0 deletions dynamics/apis/invoice_line_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class PurchaseInvoiceLineItems(ApiBase):
POST_PURCHASE_INVOICE_LINEITEM = '/purchaseInvoices({0})/purchaseInvoiceLines'
BULK_POST_PURCHASE_INVOICE_LINEITEM = 'purchaseInvoices({0})/purchaseInvoiceLines'
DELETE_PURCHASE_INVOICE_LINEITEM = '/purchaseInvoiceLines({0})'
PURCHASE_INVOICE_SET_DIMENSION = '/purchaseInvoiceLines({0})/dimensionSetLines'


def get_all(self, purchase_invoice_id: str, **kwargs):
Expand Down Expand Up @@ -77,3 +78,16 @@ def bulk_post(self, purchase_invoice_id: str, line_items: list, company_id: str,
purchase_invoice_id=purchase_invoice_id,
company_id=company_id
)

def post_purchase_invoice_dimensions(self, purchase_invoice_item_id: str, data: dict):
"""
Create dimension set line for a purchase invoice item
Parameters:
purchase_invoice_item_id: Id of the Purchase Invoice Item (str)
data: Payload to be posted (dict)
:return:
"""

return self._post_request(
data, PurchaseInvoiceLineItems.PURCHASE_INVOICE_SET_DIMENSION.format(purchase_invoice_item_id)
)
13 changes: 13 additions & 0 deletions dynamics/apis/journal_line_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class JournalLineItem(ApiBase):
POST_JOURNAL_LINE_ITEMS = '/journals({0})/journalLines'
BULK_POST_JOURNAL_LINEITEM = 'journals({0})/journalLines'
DELETE_JOURNAL_LINE_ITEMS = '/journalLines({0})'
JOUNRAL_ENTRY_SET_DIMENSION = '/journalLines({0})/dimensionSetLines'

def get_all(self, jounal_id, **kwargs):
"""
Expand Down Expand Up @@ -72,3 +73,15 @@ def bulk_post(self, journal_id: str, line_items: list, company_id: str, isolatio
isolation=isolation,
company_id=company_id
)

def post_journal_entry_dimensions(self, journal_line_item_id: str, data: dict):
"""
Create dimension set line for a journal line item
Parameters:
journal_line_item_id: Id of the Journal Line Item (str)
data: Payload to be posted (dict)
"""

return self._post_request(
data, JournalLineItem.JOUNRAL_ENTRY_SET_DIMENSION.format(journal_line_item_id)
)
14 changes: 11 additions & 3 deletions dynamics/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def __init__(
self.attachments = Attachments()
self.employees = Employees()
self.locations = Locations()
self.dimensions = Dimensions()
self.bank_accounts = BankAccounts()

# Get and set the access token
access_token = self.__refresh_access_token()
Expand All @@ -68,7 +70,9 @@ def update_access_token(self, access_token: str):
self.purchase_invoice_line_items,
self.attachments,
self.employees,
self.locations
self.locations,
self.dimensions,
self.bank_accounts,
]

# Update access tokens in all API instances
Expand All @@ -93,7 +97,9 @@ def set_batch_url(self):
self.purchase_invoice_line_items,
self.attachments,
self.employees,
self.locations
self.locations,
self.dimensions,
self.bank_accounts,
]

# Set batch URL for all API instances
Expand All @@ -120,7 +126,9 @@ def set_server_url(self):
self.purchase_invoice_line_items,
self.attachments,
self.employees,
self.locations
self.locations,
self.dimensions,
self.bank_accounts,
]

# Set base URL for all API instances
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name='ms-dynamics-business-central-sdk',
version='1.5.2',
version='1.6.0',
author='Shwetabh Kumar',
author_email='shwetabh.kumar@fyle.in',
description='Python SDK for accessing Dynamics APIs',
Expand Down

0 comments on commit a4898f6

Please sign in to comment.