Add make_corepos_api()
convenience function
This commit is contained in:
parent
67618d4784
commit
1be258246c
35
rattail_corepos/corepos/api.py
Normal file
35
rattail_corepos/corepos/api.py
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
################################################################################
|
||||||
|
"""
|
||||||
|
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)
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2020 Lance Edgar
|
# Copyright © 2010-2021 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -24,11 +24,10 @@
|
||||||
CORE-POS model importers (webservices API)
|
CORE-POS model importers (webservices API)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from corepos.api import CoreWebAPI
|
|
||||||
|
|
||||||
from rattail import importing
|
from rattail import importing
|
||||||
from rattail.util import data_diffs
|
from rattail.util import data_diffs
|
||||||
from rattail_corepos.corepos.util import get_core_members
|
from rattail_corepos.corepos.util import get_core_members
|
||||||
|
from rattail_corepos.corepos.api import make_corepos_api
|
||||||
|
|
||||||
|
|
||||||
class ToCoreAPI(importing.Importer):
|
class ToCoreAPI(importing.Importer):
|
||||||
|
@ -46,8 +45,7 @@ class ToCoreAPI(importing.Importer):
|
||||||
self.establish_api()
|
self.establish_api()
|
||||||
|
|
||||||
def establish_api(self):
|
def establish_api(self):
|
||||||
url = self.config.require('corepos.api', 'url')
|
self.api = self.make_corepos_api(self.config)
|
||||||
self.api = CoreWebAPI(url)
|
|
||||||
|
|
||||||
def ensure_fields(self, data):
|
def ensure_fields(self, data):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
################################################################################
|
################################################################################
|
||||||
#
|
#
|
||||||
# Rattail -- Retail Software Framework
|
# Rattail -- Retail Software Framework
|
||||||
# Copyright © 2010-2020 Lance Edgar
|
# Copyright © 2010-2021 Lance Edgar
|
||||||
#
|
#
|
||||||
# This file is part of Rattail.
|
# This file is part of Rattail.
|
||||||
#
|
#
|
||||||
|
@ -26,10 +26,10 @@ DataSync for Rattail DB
|
||||||
|
|
||||||
from sqlalchemy.orm.exc import NoResultFound
|
from sqlalchemy.orm.exc import NoResultFound
|
||||||
|
|
||||||
from corepos.api import CoreWebAPI
|
|
||||||
from corepos.db.office_op import Session as CoreSession, model as corepos
|
from corepos.db.office_op import Session as CoreSession, model as corepos
|
||||||
|
|
||||||
from rattail.datasync import NewDataSyncImportConsumer
|
from rattail.datasync import NewDataSyncImportConsumer
|
||||||
|
from rattail_corepos.corepos.api import make_corepos_api
|
||||||
|
|
||||||
|
|
||||||
class FromCOREAPIToRattail(NewDataSyncImportConsumer):
|
class FromCOREAPIToRattail(NewDataSyncImportConsumer):
|
||||||
|
@ -46,8 +46,7 @@ class FromCOREAPIToRattail(NewDataSyncImportConsumer):
|
||||||
self.establish_api()
|
self.establish_api()
|
||||||
|
|
||||||
def establish_api(self):
|
def establish_api(self):
|
||||||
url = self.config.require('corepos.api', 'url')
|
self.api = make_corepos_api(self.config)
|
||||||
self.api = CoreWebAPI(url)
|
|
||||||
|
|
||||||
def process_changes(self, session, changes):
|
def process_changes(self, session, changes):
|
||||||
if self.runas_username:
|
if self.runas_username:
|
||||||
|
|
|
@ -30,8 +30,6 @@ import logging
|
||||||
|
|
||||||
from sqlalchemy import orm
|
from sqlalchemy import orm
|
||||||
|
|
||||||
from corepos.api import CoreWebAPI
|
|
||||||
|
|
||||||
from rattail import importing
|
from rattail import importing
|
||||||
from rattail.gpc import GPC
|
from rattail.gpc import GPC
|
||||||
from rattail.util import OrderedDict
|
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.db.util import normalize_full_name
|
||||||
from rattail_corepos import importing as corepos_importing
|
from rattail_corepos import importing as corepos_importing
|
||||||
from rattail_corepos.corepos.util import get_core_members
|
from rattail_corepos.corepos.util import get_core_members
|
||||||
|
from rattail_corepos.corepos.api import make_corepos_api
|
||||||
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
@ -83,8 +82,7 @@ class FromCOREPOSAPI(importing.Importer):
|
||||||
self.establish_api()
|
self.establish_api()
|
||||||
|
|
||||||
def establish_api(self):
|
def establish_api(self):
|
||||||
url = self.config.require('corepos.api', 'url')
|
self.api = make_corepos_api(self.config)
|
||||||
self.api = CoreWebAPI(url)
|
|
||||||
|
|
||||||
def get_core_members(self):
|
def get_core_members(self):
|
||||||
return get_core_members(self.api, progress=self.progress)
|
return get_core_members(self.api, progress=self.progress)
|
||||||
|
|
Loading…
Reference in a new issue