Move "direct DB" CORE importer logic, to subpackage

i.e. `rattail_corepos.corepos.importing.db` is now the place for direct DB
importers, and `rattail_corepos.corepos.importing` will become the place for
proper API-based importers
This commit is contained in:
Lance Edgar 2020-03-03 23:25:37 -06:00
parent 0298e63384
commit 75ba08b9fc
10 changed files with 246 additions and 126 deletions

View file

@ -80,7 +80,7 @@ class ExportCore(commands.ImportSubcommand):
"""
name = 'export-core'
description = __doc__.strip()
default_handler_spec = 'rattail_corepos.corepos.importing.corepos:FromCoreToCoreExport'
default_handler_spec = 'rattail_corepos.corepos.importing.db.corepos:FromCoreToCoreExport'
default_dbkey = 'host'
def get_handler_factory(self, **kwargs):
@ -111,7 +111,7 @@ class ExportCSV(commands.ExportFileSubcommand):
"""
name = 'export-csv'
description = __doc__.strip()
default_handler_spec = 'rattail_corepos.corepos.importing.exporters:FromCoreToCSV'
default_handler_spec = 'rattail_corepos.corepos.importing.db.exporters:FromCoreToCSV'
def get_handler_factory(self, **kwargs):
if self.config:
@ -130,7 +130,7 @@ class ImportCore(ImportToCore):
name = 'import-core'
description = __doc__.strip()
handler_key = 'corepos'
default_handler_spec = 'rattail_corepos.corepos.importing.corepos:FromCoreToCoreImport'
default_handler_spec = 'rattail_corepos.corepos.importing.db.corepos:FromCoreToCoreImport'
accepts_dbkey_param = True
def add_parser_args(self, parser):
@ -155,7 +155,7 @@ class ImportCSV(commands.ImportFileSubcommand):
"""
name = 'import-csv'
description = __doc__.strip()
default_handler_spec = 'rattail_corepos.corepos.importing.csv:FromCSVToCore'
default_handler_spec = 'rattail_corepos.corepos.importing.db.csv:FromCSVToCore'
def add_parser_args(self, parser):
super(ImportCSV, self).add_parser_args(parser)

View file

@ -1,8 +1,27 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 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/>.
#
################################################################################
"""
Importing data into CORE-POS
"""
from __future__ import unicode_literals, absolute_import
from . import model

View file

@ -0,0 +1,27 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 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/>.
#
################################################################################
"""
Importing data into CORE-POS (direct DB)
"""
from . import model

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,13 +24,12 @@
CORE-POS -> CORE-POS data import
"""
from __future__ import unicode_literals, absolute_import
from corepos.db.office_op import Session as CoreSession
from rattail.importing.handlers import FromSQLAlchemyHandler, ToSQLAlchemyHandler
from rattail.importing.sqlalchemy import FromSQLAlchemySameToSame
from rattail.util import OrderedDict
from rattail_corepos.db import Session as CoreSession
from rattail_corepos.corepos import importing as corepos_importing
from rattail_corepos.corepos.importing import db as corepos_importing
class FromCoreHandler(FromSQLAlchemyHandler):

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,14 +24,12 @@
CSV -> CORE data import
"""
from __future__ import unicode_literals, absolute_import
from corepos.db import model as corepos, Session as CoreSession
from corepos.db.office_op import model as corepos, Session as CoreSession
from rattail.importing.handlers import FromFileHandler
from rattail.importing.csv import FromCSVToSQLAlchemyMixin
from rattail_corepos.corepos.importing.model import ToCore
from rattail_corepos.corepos.importing.corepos import ToCoreHandler
from rattail_corepos.corepos.importing.db.model import ToCore
from rattail_corepos.corepos.importing.db.corepos import ToCoreHandler
class FromCSVToCore(FromCSVToSQLAlchemyMixin, FromFileHandler, ToCoreHandler):

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2019 Lance Edgar
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,13 +24,11 @@
CORE-POS Data Export
"""
from __future__ import unicode_literals, absolute_import
from corepos.db import model as corepos
from corepos.db.office_op import model as corepos
from rattail.importing.handlers import ToCSVHandler
from rattail.importing.exporters import FromSQLAlchemyToCSVMixin
from rattail_corepos.corepos.importing.corepos import FromCoreHandler, FromCore
from rattail_corepos.corepos.importing.db.corepos import FromCoreHandler, FromCore
class FromCoreToCSV(FromSQLAlchemyToCSVMixin, FromCoreHandler, ToCSVHandler):

View file

@ -0,0 +1,133 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 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 model importers (direct DB)
.. warning::
All classes in this module are "direct DB" importers, which will write
directly to MySQL. They are meant to be used in dry-run mode only, and/or
for sample data import to a dev system etc. They are *NOT* meant for
production use, as they will completely bypass any CORE business rules logic
which may exist.
"""
from sqlalchemy.orm.exc import NoResultFound
from rattail import importing
from corepos.db.office_op import model as corepos
from corepos.db.office_trans import model as coretrans
class ToCore(importing.ToSQLAlchemy):
"""
Base class for all CORE "operational" model importers.
"""
# TODO: should we standardize on the 'id' primary key? (can we even?)
# key = 'id'
class ToCoreTrans(importing.ToSQLAlchemy):
"""
Base class for all CORE "transaction" model importers
"""
########################################
# CORE Operational
########################################
class DepartmentImporter(ToCore):
model_class = corepos.Department
key = 'number'
class SubdepartmentImporter(ToCore):
model_class = corepos.Subdepartment
key = 'number'
class VendorImporter(ToCore):
model_class = corepos.Vendor
key = 'id'
class VendorContactImporter(ToCore):
model_class = corepos.VendorContact
key = 'vendor_id'
class ProductImporter(ToCore):
model_class = corepos.Product
key = 'id'
class ProductFlagImporter(ToCore):
model_class = corepos.ProductFlag
key = 'bit_number'
class EmployeeImporter(ToCore):
model_class = corepos.Employee
key = 'number'
class CustomerImporter(ToCore):
model_class = corepos.Customer
key = 'id'
class MemberTypeImporter(ToCore):
model_class = corepos.MemberType
key = 'id'
class MemberInfoImporter(ToCore):
model_class = corepos.MemberInfo
key = 'card_number'
class MemberDateImporter(ToCore):
model_class = corepos.MemberDate
key = 'card_number'
class MemberContactImporter(ToCore):
model_class = corepos.MemberContact
key = 'card_number'
class HouseCouponImporter(ToCore):
model_class = corepos.HouseCoupon
key = 'coupon_id'
########################################
# CORE Transactions
########################################
class TransactionDetailImporter(ToCoreTrans):
"""
CORE-POS transaction data importer.
"""
model_class = coretrans.TransactionDetail

View file

@ -1,22 +1,40 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 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/>.
#
################################################################################
"""
Square -> CORE-POS data importing
"""
from __future__ import unicode_literals, absolute_import
import re
import datetime
import decimal
import six
import sqlalchemy as sa
from corepos.trans.db import Session as CoreTransSession, model as coretrans
from corepos.db.office_trans import Session as CoreTransSession, model as coretrans
from rattail import importing
from rattail.util import OrderedDict
from rattail_corepos.corepos import importing as corepos_importing
from rattail_corepos.corepos.importing import db as corepos_importing
class FromSquareToCoreTrans(importing.ToSQLAlchemyHandler):

View file

@ -1,30 +1,36 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 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 model importers
.. warning::
As of this writing, most classes in this module are "direct DB" importers,
which will write directly to MySQL. They are meant to be used in dry-run
mode only, and/or for sample data import to a dev system etc. They are
*NOT* meant for production use, as they will completely bypass any CORE
business rules logic which may exist.
However some of the importers will be refactored, so they directly use the
CORE API for *writing* data (although they may continue to read directly
from the DB). The hope is that *all* existing importers can be refactored
to write via API instead of DB, so for now all importers are left intact
until they can be dealt with (hopefully refactored, but if not, then
removed).
CORE-POS model importers (webservices API)
"""
from sqlalchemy.orm.exc import NoResultFound
from rattail import importing
from corepos.db.office_op import model as corepos
from corepos.db.office_trans import model as coretrans
from corepos.api import CoreWebAPI
from rattail import importing
class ToCore(importing.ToSQLAlchemy):
"""
@ -67,27 +73,10 @@ class ToCore(importing.ToSQLAlchemy):
pass
class ToCoreTrans(importing.ToSQLAlchemy):
"""
Base class for all CORE "transaction" model importers
"""
########################################
# CORE Operational
########################################
class DepartmentImporter(ToCore):
model_class = corepos.Department
key = 'number'
class SubdepartmentImporter(ToCore):
model_class = corepos.Subdepartment
key = 'number'
class VendorImporter(ToCore):
"""
Vendor model importer for CORE-POS
"""
model_class = corepos.Vendor
key = 'vendorID'
supported_fields = [
@ -119,64 +108,3 @@ class VendorImporter(ToCore):
vendorID = data.pop('vendorID')
self.api.set_vendor(vendorID, **data)
return data
class VendorContactImporter(ToCore):
model_class = corepos.VendorContact
key = 'vendor_id'
class ProductImporter(ToCore):
model_class = corepos.Product
key = 'id'
class ProductFlagImporter(ToCore):
model_class = corepos.ProductFlag
key = 'bit_number'
class EmployeeImporter(ToCore):
model_class = corepos.Employee
key = 'number'
class CustomerImporter(ToCore):
model_class = corepos.Customer
key = 'id'
class MemberTypeImporter(ToCore):
model_class = corepos.MemberType
key = 'id'
class MemberInfoImporter(ToCore):
model_class = corepos.MemberInfo
key = 'card_number'
class MemberDateImporter(ToCore):
model_class = corepos.MemberDate
key = 'card_number'
class MemberContactImporter(ToCore):
model_class = corepos.MemberContact
key = 'card_number'
class HouseCouponImporter(ToCore):
model_class = corepos.HouseCoupon
key = 'coupon_id'
########################################
# CORE Transactions
########################################
class TransactionDetailImporter(ToCoreTrans):
"""
CORE-POS transaction data importer.
"""
model_class = coretrans.TransactionDetail

View file

@ -30,7 +30,7 @@ from rattail import importing
from rattail.db import model
from rattail.util import OrderedDict
from rattail_corepos.corepos import importing as corepos_importing
from rattail_corepos.corepos.importing.corepos import ToCoreHandler
from rattail_corepos.corepos.importing.db.corepos import ToCoreHandler
log = logging.getLogger(__name__)