Commit cebad4ec authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Add support for konto and kontoplan endpoints

parent 5b98749c
Pipeline #29317 passed with stage
in 1 minute and 6 seconds
......@@ -21,6 +21,10 @@ rest:
url: arbeidsordre/v1
gl07logs:
url: objekter/gl07logs/v1
kontoplan:
url: kontoplan/v1
konto:
url: kontoplan/v1
import_service:
credentials:
......
......@@ -45,6 +45,12 @@ def config(base_url):
},
'gl07logs': {
'headers': {}
},
'konto': {
'headers': {}
},
'kontoplan': {
'headers': {}
}
}
},
......@@ -68,6 +74,8 @@ def config_no_overrides(base_url):
'bruker': {},
'arbeidsordre': {},
'gl07logs': {},
'konto': {},
'kontoplan': {},
},
},
'import_service': None,
......@@ -168,6 +176,11 @@ def gl07logs_data():
return load_json_file('gl07logs.json')
@pytest.fixture
def konto():
return load_json_file('konto.json')
@pytest.fixture
def transaction_report_data():
return load_xml('transaction_report.xml')
......
[
{
"account": "2940",
"accountGroup": "294",
"accountName": "Skyldige feriepenger, opptjent tidligere år (SAP)",
"accountRule": 7,
"accountRuleName": "Konteringsregel 7",
"accountType": "GL",
"companyId": "72",
"headOfficeAccount": "",
"periodFrom": 199401,
"periodTo": 209912,
"status": "N",
"lastUpdated": {
"updatedAt": "2019-07-02T09:32:53.570",
"updatedBy": "R.ARFO"
},
"contactPoints": [],
"relatedValues": [
{
"dateFrom": "1900-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 100,
"relatedValue": "294",
"relationGroup": "",
"relationId": "MNXA",
"relationName": "ARTSKONTO",
"unitValue": 0
},
{
"dateFrom": "1900-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 100,
"relatedValue": "294",
"relationGroup": "",
"relationId": "Q1",
"relationName": "UGR",
"unitValue": 0
},
{
"dateFrom": "1900-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 100,
"relatedValue": "GJEL",
"relationGroup": "",
"relationId": "Q10",
"relationName": "KATEGORI",
"unitValue": 0
},
{
"dateFrom": "1900-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 100,
"relatedValue": "NEI",
"relationGroup": "",
"relationId": "Q30",
"relationName": "EGENFIN",
"unitValue": 0
},
{
"dateFrom": "1900-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 100,
"relatedValue": "NEI",
"relationGroup": "",
"relationId": "Q31",
"relationName": "INDIRKOST",
"unitValue": 0
},
{
"dateFrom": "1900-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 100,
"relatedValue": "1",
"relationGroup": "",
"relationId": "Y2",
"relationName": "SAP",
"unitValue": 0
}
],
"customFieldGroups": {}
}
]
......@@ -14,6 +14,7 @@ from ubw_client.models import (
Prosjekt,
ServerProcessResponse,
ServerProcessResult,
Konto,
)
......@@ -199,6 +200,17 @@ def test_get_gl07logs(client, base_url, requests_mock, gl07logs_data):
assert received == expected
def test_get_konto(client, requests_mock, konto):
company_id = "72"
account_id = "2943"
requests_mock.get(
f"https://example.com/kontoplan/v1/{company_id}/{account_id}",
json=konto,
)
received = client.get_konto(company_id, account_id)
expected = Konto(**konto[0])
def test_get_transaction_report(
client, base_url, requests_mock, transaction_report_data
):
......
......@@ -87,3 +87,31 @@ def test_brukere_url_override_wo_trailing_slash(config_no_overrides):
client = get_client(**config_no_overrides)
url = client.urls.get_bruker("72")
assert url == "https://example.com/nonbase/brukere/72"
def test_konto_url_no_override_w_trailing_slash(config_no_overrides):
config_no_overrides["rest"]["base_url"] += "base/" # trailing slash
client = get_client(**config_no_overrides)
url = client.urls.get_konto("72", "2942")
assert url == "https://example.com/base/kontoplan/v1/72/2942"
def test_konto_url_no_override_wo_trailing_slash(config_no_overrides):
config_no_overrides["rest"]["base_url"] += "base" # no trailing slash
client = get_client(**config_no_overrides)
url = client.urls.get_konto("72", "2942")
assert url == "https://example.com/base/kontoplan/v1/72/2942"
def test_kontoplan_url_no_override_w_trailing_slash(config_no_overrides):
config_no_overrides["rest"]["base_url"] += "base/" # trailing slash
client = get_client(**config_no_overrides)
url = client.urls.get_kontoplan("72")
assert url == "https://example.com/base/kontoplan/v1/72"
def test_kontoplan_url_no_override_wo_trailing_slash(config_no_overrides):
config_no_overrides["rest"]["base_url"] += "base" # no trailing slash
client = get_client(**config_no_overrides)
url = client.urls.get_kontoplan("72")
assert url == "https://example.com/base/kontoplan/v1/72"
......@@ -10,6 +10,7 @@ from zeep.plugins import HistoryPlugin
from urllib.parse import urljoin, urlparse
from . import models
from .models import Konto
logger = logging.getLogger(__name__)
......@@ -64,6 +65,16 @@ class Endpoints:
self.rest.endpoints.gl07logs.url or 'objekter/gl07logs', company_id
)
def get_kontoplan(self, companyid: str):
return self._prepend_base_url(
self.rest.endpoints.kontoplan.url or 'kontoplan/v1', companyid
)
def get_konto(self, company_id: str, konto: str):
return self._prepend_base_url(
self.rest.endpoints.konto.url or 'kontoplan/v1', company_id, konto
)
def _create_transaction_report(transaction_result_response) -> models.ServerProcessResult:
"""Create transaction report from dict or zeep object"""
......@@ -414,6 +425,38 @@ class UBWClient:
response = self.get(url, params=params, headers=headers)
return [models.GL07Log.from_dict(log) for log in response]
def get_kontoplan(
self,
company_id: str,
account_group: str = None,
):
"""
Send get request to kontoplan api endpoint
TODO: Add support for more filters
"""
url = self.urls.get_kontoplan(company_id)
headers = {}
if self.config.rest:
headers = self.config.rest.endpoints.kontoplan.headers
params = {}
if account_group:
params['filter'] = f"accountGroup eq '{account_group}'"
response = self.get(url, params=params, headers=headers)
return [Konto(**account) for account in response]
def get_konto(
self,
company_id: str,
konto: str,
):
url = self.urls.get_konto(company_id, konto)
headers = self.config.rest.endpoints.konto.headers
response = self.get(url, headers=headers)[0]
return Konto(**response)
def get_client(**config):
return UBWClient(models.UbwClientConfig(**config))
......@@ -75,6 +75,8 @@ class UbwRestEndpoints(BaseModel):
bruker: UbwRestEndpoint
arbeidsordre: UbwRestEndpoint
gl07logs: UbwRestEndpoint
kontoplan: UbwRestEndpoint
konto: UbwRestEndpoint
class UbwRestBase(BaseModel):
......@@ -733,3 +735,29 @@ class GL07Log(BaseModel):
class Config:
alias_generator = to_lower_camel
allow_population_by_field_name = True
class KontoCustomFieldGroups(BaseModel):
pass
class Konto(BaseModel):
account: str
account_group: str
account_name: str
account_rule: int
account_rule_name: str
account_type: str
company_id: str
head_office_account: str
period_from: int
period_to: int
status: str
last_updated: UpdatedInfo
contact_points: typing.List[ContactPoints]
related_values: typing.List[RelatedValue]
custom_field_groups: KontoCustomFieldGroups
class Config:
alias_generator = to_lower_camel
allow_population_by_field_name = True
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment