diff --git a/tfsoffice/__init__.py b/tfsoffice/__init__.py index 7625db2..a9d21c5 100644 --- a/tfsoffice/__init__.py +++ b/tfsoffice/__init__.py @@ -3,7 +3,7 @@ from tfsoffice.client import Client # noqa __title__ = 'tfsoffice' -__version__ = '0.1.9998' +__version__ = '0.1.9999' __copyright__ = 'Copyright 2017 Dataselskapet AS' __author__ = 'rune@loyning.net' __all__ = ['Client', ] diff --git a/tfsoffice/client.py b/tfsoffice/client.py index 62b7fc7..4839157 100644 --- a/tfsoffice/client.py +++ b/tfsoffice/client.py @@ -132,6 +132,9 @@ class Client: 'TransactionService.asmx?WSDL', } + _client_information = {} + _country_code = '' + def __init__(self, username, password, applicationid, identityid=None, token_id=None, faults=True, **options): # noqa """ Initialize a Client object with session, optional auth handler, and options @@ -140,6 +143,7 @@ def __init__(self, username, password, applicationid, identityid=None, token_id= self._faults = faults self._clients = {} self._headers = None + self._username = username if 'session_id' in options: session_id = options['session_id'] @@ -182,6 +186,10 @@ def __init__(self, username, password, applicationid, identityid=None, token_id= for name, Klass in list(RESOURCE_CLASSES.items()): setattr(self, name, Klass(self)) + # load client information to get country code + self._client_information = self.client.get_client_information() + self._country_code = self._client_information.get('Country') or '' + def _authenticate( self, username, diff --git a/tfsoffice/resources/accounts.py b/tfsoffice/resources/accounts.py index f7a5173..f8f9e67 100644 --- a/tfsoffice/resources/accounts.py +++ b/tfsoffice/resources/accounts.py @@ -256,6 +256,24 @@ def create_bundlelist(self, data): [e for e in entries if e.get('stamp_no', None) == stamp_no] ) + # get bank details about the vendor + customer_ids = list(set([e['customer_id'] for e in entries])) + giro_numbers = list(set([e['giro_number'] for e in entries])) + + if self._client._country_code.upper() == 'SE' and customer_ids and giro_numbers: + # load vendor to get payment info from CRM + vendor = self._client.companies.find_by_id(customer_ids[0]) + + # if giro number does not match value in CRM - change it + if vendor.get('BankAccountNo') != giro_numbers[0]: + stored_value = vendor.get('BankAccountNo').replace('-', '') + giro_number = giro_numbers[0].replace('-', '') + + if stored_value == giro_number: + for e in entries: + e['bankaccount'] = vendor.get('BankAccountNo') + print(entries) + # # Add CurrencyRate to entries #