Add importer, datasync for CORE-POS (API) -> Rattail
This commit is contained in:
		
							parent
							
								
									9aefbc872e
								
							
						
					
					
						commit
						ab8894ef0d
					
				
					 5 changed files with 250 additions and 35 deletions
				
			
		| 
						 | 
				
			
			@ -1,29 +0,0 @@
 | 
			
		|||
# -*- coding: utf-8; -*-
 | 
			
		||||
################################################################################
 | 
			
		||||
#
 | 
			
		||||
#  Rattail -- Retail Software Framework
 | 
			
		||||
#  Copyright © 2010-2018 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 Interface
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
from __future__ import unicode_literals, absolute_import
 | 
			
		||||
 | 
			
		||||
from rattail_corepos._version import __version__
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
################################################################################
 | 
			
		||||
#
 | 
			
		||||
#  Rattail -- Retail Software Framework
 | 
			
		||||
#  Copyright © 2010-2018 Lance Edgar
 | 
			
		||||
#  Copyright © 2010-2020 Lance Edgar
 | 
			
		||||
#
 | 
			
		||||
#  This file is part of Rattail.
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			@ -21,23 +21,47 @@
 | 
			
		|||
#
 | 
			
		||||
################################################################################
 | 
			
		||||
"""
 | 
			
		||||
DataSync for Milo
 | 
			
		||||
DataSync for Rattail DB
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
from __future__ import unicode_literals, absolute_import
 | 
			
		||||
 | 
			
		||||
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 corepos.db import Session as CoreSession, model as corepos
 | 
			
		||||
 | 
			
		||||
class FromCOREAPIToRattail(NewDataSyncImportConsumer):
 | 
			
		||||
    """
 | 
			
		||||
    Consumer for CORE POS (API) -> Rattail datasync
 | 
			
		||||
    """
 | 
			
		||||
    handler_spec = 'rattail_corepos.importing.corepos.api:FromCOREPOSToRattail'
 | 
			
		||||
 | 
			
		||||
    def setup(self):
 | 
			
		||||
        super(FromCOREAPIToRattail, self).setup()
 | 
			
		||||
        self.establish_api()
 | 
			
		||||
 | 
			
		||||
    def establish_api(self):
 | 
			
		||||
        url = self.config.require('corepos.api', 'url')
 | 
			
		||||
        self.api = CoreWebAPI(url)
 | 
			
		||||
 | 
			
		||||
    def get_host_object(self, session, change):
 | 
			
		||||
        if change.payload_type == 'Department':
 | 
			
		||||
            return self.api.get_department(change.payload_key)
 | 
			
		||||
        if change.payload_type == 'Subdepartment':
 | 
			
		||||
            return self.api.get_subdepartment(change.payload_key)
 | 
			
		||||
        if change.payload_type == 'Vendor':
 | 
			
		||||
            return self.api.get_vendor(change.payload_key)
 | 
			
		||||
        if change.payload_type == 'Product':
 | 
			
		||||
            return self.api.get_product(change.payload_key)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class FromCOREPOSToRattailBase(NewDataSyncImportConsumer):
 | 
			
		||||
    """
 | 
			
		||||
    Base class for CORE POS -> Rattail data sync consumers.
 | 
			
		||||
    """
 | 
			
		||||
    handler_spec = 'rattail_corepos.importing.corepos:FromCOREPOSToRattail'
 | 
			
		||||
    handler_spec = 'rattail_corepos.importing.corepos.db:FromCOREPOSToRattail'
 | 
			
		||||
 | 
			
		||||
    def begin_transaction(self):
 | 
			
		||||
        self.corepos_session = CoreSession()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue