diff --git a/rattail_corepos/corepos/api.py b/rattail_corepos/corepos/api.py new file mode 100644 index 0000000..69d98c5 --- /dev/null +++ b/rattail_corepos/corepos/api.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8; -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2021 Lance Edgar +# +# This file is part of Rattail. +# +# Rattail is free software: you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation, either version 3 of the License, or (at your option) any later +# version. +# +# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +# details. +# +# You should have received a copy of the GNU General Public License along with +# Rattail. If not, see . +# +################################################################################ +""" +CORE-POS API +""" + +from corepos.api import CoreWebAPI + + +def make_corepos_api(config): + """ + Make and return a new CORE-POS API client object. + """ + url = config.require('corepos.api', 'url') + return CoreWebAPI(url) diff --git a/rattail_corepos/corepos/importing/model.py b/rattail_corepos/corepos/importing/model.py index 9c4db31..0b1b452 100644 --- a/rattail_corepos/corepos/importing/model.py +++ b/rattail_corepos/corepos/importing/model.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2020 Lance Edgar +# Copyright © 2010-2021 Lance Edgar # # This file is part of Rattail. # @@ -24,11 +24,10 @@ CORE-POS model importers (webservices API) """ -from corepos.api import CoreWebAPI - from rattail import importing from rattail.util import data_diffs from rattail_corepos.corepos.util import get_core_members +from rattail_corepos.corepos.api import make_corepos_api class ToCoreAPI(importing.Importer): @@ -46,8 +45,7 @@ class ToCoreAPI(importing.Importer): self.establish_api() def establish_api(self): - url = self.config.require('corepos.api', 'url') - self.api = CoreWebAPI(url) + self.api = self.make_corepos_api(self.config) def ensure_fields(self, data): """ diff --git a/rattail_corepos/datasync/rattail.py b/rattail_corepos/datasync/rattail.py index 785cd46..4495f4e 100644 --- a/rattail_corepos/datasync/rattail.py +++ b/rattail_corepos/datasync/rattail.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2020 Lance Edgar +# Copyright © 2010-2021 Lance Edgar # # This file is part of Rattail. # @@ -26,10 +26,10 @@ DataSync for Rattail DB from sqlalchemy.orm.exc import NoResultFound -from corepos.api import CoreWebAPI from corepos.db.office_op import Session as CoreSession, model as corepos from rattail.datasync import NewDataSyncImportConsumer +from rattail_corepos.corepos.api import make_corepos_api class FromCOREAPIToRattail(NewDataSyncImportConsumer): @@ -46,8 +46,7 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer): self.establish_api() def establish_api(self): - url = self.config.require('corepos.api', 'url') - self.api = CoreWebAPI(url) + self.api = make_corepos_api(self.config) def process_changes(self, session, changes): if self.runas_username: diff --git a/rattail_corepos/importing/corepos/api.py b/rattail_corepos/importing/corepos/api.py index 287936a..a762f2b 100644 --- a/rattail_corepos/importing/corepos/api.py +++ b/rattail_corepos/importing/corepos/api.py @@ -30,8 +30,6 @@ import logging from sqlalchemy import orm -from corepos.api import CoreWebAPI - from rattail import importing from rattail.gpc import GPC from rattail.util import OrderedDict @@ -40,6 +38,7 @@ from rattail.core import get_uuid from rattail.db.util import normalize_full_name from rattail_corepos import importing as corepos_importing from rattail_corepos.corepos.util import get_core_members +from rattail_corepos.corepos.api import make_corepos_api log = logging.getLogger(__name__) @@ -83,8 +82,7 @@ class FromCOREPOSAPI(importing.Importer): self.establish_api() def establish_api(self): - url = self.config.require('corepos.api', 'url') - self.api = CoreWebAPI(url) + self.api = make_corepos_api(self.config) def get_core_members(self): return get_core_members(self.api, progress=self.progress)