Changeset - 1be258246cec
[Not reviewed]
0 3 1
Lance Edgar - 4 years ago 2021-02-09 14:28:38
lance@edbob.org
Add `make_corepos_api()` convenience function
4 files changed with 43 insertions and 13 deletions:
0 comments (0 inline, 0 general) First comment
rattail_corepos/corepos/api.py
Show inline comments
 
new file 100644
 
# -*- 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)
rattail_corepos/corepos/importing/model.py
Show inline comments
 
@@ -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):
 
        """
rattail_corepos/datasync/rattail.py
Show inline comments
 
@@ -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:
rattail_corepos/importing/corepos/api.py
Show inline comments
 
@@ -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)
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now