From 75ba08b9fc68afdf71ed72e2fe29b4400b9e1440 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 3 Mar 2020 23:25:37 -0600 Subject: [PATCH] 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 --- rattail_corepos/corepos/commands.py | 8 +- rattail_corepos/corepos/importing/__init__.py | 23 ++- .../corepos/importing/db/__init__.py | 27 ++++ .../corepos/importing/{ => db}/corepos.py | 7 +- .../corepos/importing/{ => db}/csv.py | 10 +- .../corepos/importing/{ => db}/exporters.py | 8 +- rattail_corepos/corepos/importing/db/model.py | 133 ++++++++++++++++++ .../corepos/importing/{ => db}/square.py | 28 +++- rattail_corepos/corepos/importing/model.py | 126 ++++------------- rattail_corepos/corepos/importing/rattail.py | 2 +- 10 files changed, 246 insertions(+), 126 deletions(-) create mode 100644 rattail_corepos/corepos/importing/db/__init__.py rename rattail_corepos/corepos/importing/{ => db}/corepos.py (95%) rename rattail_corepos/corepos/importing/{ => db}/csv.py (83%) rename rattail_corepos/corepos/importing/{ => db}/exporters.py (86%) create mode 100644 rattail_corepos/corepos/importing/db/model.py rename rattail_corepos/corepos/importing/{ => db}/square.py (82%) diff --git a/rattail_corepos/corepos/commands.py b/rattail_corepos/corepos/commands.py index 5008df6..d05d82c 100644 --- a/rattail_corepos/corepos/commands.py +++ b/rattail_corepos/corepos/commands.py @@ -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) diff --git a/rattail_corepos/corepos/importing/__init__.py b/rattail_corepos/corepos/importing/__init__.py index 62949e3..9f5f2cb 100644 --- a/rattail_corepos/corepos/importing/__init__.py +++ b/rattail_corepos/corepos/importing/__init__.py @@ -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 . +# +################################################################################ """ Importing data into CORE-POS """ -from __future__ import unicode_literals, absolute_import - from . import model diff --git a/rattail_corepos/corepos/importing/db/__init__.py b/rattail_corepos/corepos/importing/db/__init__.py new file mode 100644 index 0000000..6299241 --- /dev/null +++ b/rattail_corepos/corepos/importing/db/__init__.py @@ -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 . +# +################################################################################ +""" +Importing data into CORE-POS (direct DB) +""" + +from . import model diff --git a/rattail_corepos/corepos/importing/corepos.py b/rattail_corepos/corepos/importing/db/corepos.py similarity index 95% rename from rattail_corepos/corepos/importing/corepos.py rename to rattail_corepos/corepos/importing/db/corepos.py index d673da5..e1904f5 100644 --- a/rattail_corepos/corepos/importing/corepos.py +++ b/rattail_corepos/corepos/importing/db/corepos.py @@ -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): diff --git a/rattail_corepos/corepos/importing/csv.py b/rattail_corepos/corepos/importing/db/csv.py similarity index 83% rename from rattail_corepos/corepos/importing/csv.py rename to rattail_corepos/corepos/importing/db/csv.py index fc87710..f2f77fb 100644 --- a/rattail_corepos/corepos/importing/csv.py +++ b/rattail_corepos/corepos/importing/db/csv.py @@ -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): diff --git a/rattail_corepos/corepos/importing/exporters.py b/rattail_corepos/corepos/importing/db/exporters.py similarity index 86% rename from rattail_corepos/corepos/importing/exporters.py rename to rattail_corepos/corepos/importing/db/exporters.py index f4c024d..5357e39 100644 --- a/rattail_corepos/corepos/importing/exporters.py +++ b/rattail_corepos/corepos/importing/db/exporters.py @@ -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): diff --git a/rattail_corepos/corepos/importing/db/model.py b/rattail_corepos/corepos/importing/db/model.py new file mode 100644 index 0000000..b347ec0 --- /dev/null +++ b/rattail_corepos/corepos/importing/db/model.py @@ -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 . +# +################################################################################ +""" +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 diff --git a/rattail_corepos/corepos/importing/square.py b/rattail_corepos/corepos/importing/db/square.py similarity index 82% rename from rattail_corepos/corepos/importing/square.py rename to rattail_corepos/corepos/importing/db/square.py index c7fbc69..439978a 100644 --- a/rattail_corepos/corepos/importing/square.py +++ b/rattail_corepos/corepos/importing/db/square.py @@ -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 . +# +################################################################################ """ 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): diff --git a/rattail_corepos/corepos/importing/model.py b/rattail_corepos/corepos/importing/model.py index 52d2ce9..77a1a92 100644 --- a/rattail_corepos/corepos/importing/model.py +++ b/rattail_corepos/corepos/importing/model.py @@ -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 . +# +################################################################################ """ -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 diff --git a/rattail_corepos/corepos/importing/rattail.py b/rattail_corepos/corepos/importing/rattail.py index 0e1a996..063b4ef 100644 --- a/rattail_corepos/corepos/importing/rattail.py +++ b/rattail_corepos/corepos/importing/rattail.py @@ -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__)