From 2cf865d879c0d7d081ee6a489ff87b2489e6bd02 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 9 Jun 2023 19:53:47 -0500 Subject: [PATCH] Add `core-office import-csv` command; deprecate `crepes import-csv` --- rattail_corepos/corepos/commands.py | 33 +++++-------------- rattail_corepos/corepos/office/commands.py | 26 +++++++++++++++ .../corepos/office/importing/db/csv.py | 7 +--- rattail_corepos/emails.py | 8 +++++ setup.cfg | 3 +- 5 files changed, 46 insertions(+), 31 deletions(-) diff --git a/rattail_corepos/corepos/commands.py b/rattail_corepos/corepos/commands.py index 6a61af5..f1cccac 100644 --- a/rattail_corepos/corepos/commands.py +++ b/rattail_corepos/corepos/commands.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,13 +24,12 @@ CORE-POS commands """ -from __future__ import unicode_literals, absolute_import - import sys +import warnings from rattail import commands from rattail_corepos import __version__ -from rattail.util import load_object +from rattail_corepos.corepos.office.commands import ImportCSV def main(*args): @@ -118,24 +117,10 @@ class ImportCore(ImportToCore): return kwargs -class ImportCSV(commands.ImportFileSubcommand): - """ - Import data from CSV file(s) to CORE database - """ - name = 'import-csv' - description = __doc__.strip() - handler_key = 'to_corepos_db_office_op.from_csv.import' +class LegacyImportCSV(ImportCSV): - def add_parser_args(self, parser): - super(ImportCSV, self).add_parser_args(parser) - parser.add_argument('--dbkey', metavar='KEY', default='default', - help="Config key for database engine to be used as the \"target\" " - "CORE DB, i.e. where data will be imported *to*. This key must be " - "defined in the [rattail_corepos.db] section of your config file.") - - def get_handler_kwargs(self, **kwargs): - kwargs = super(ImportCSV, self).get_handler_kwargs(**kwargs) - if 'args' in kwargs: - args = kwargs['args'] - kwargs['dbkey'] = args.dbkey - return kwargs + def __init__(self, *args, **kwargs): + warnings.warn("the `crepes import-csv` command is deprecated; " + "please use `core-office import-csv` instead", + DeprecationWarning, stacklevel=2) + super().__init__(*args, **kwargs) diff --git a/rattail_corepos/corepos/office/commands.py b/rattail_corepos/corepos/office/commands.py index f1356f4..11c5d11 100644 --- a/rattail_corepos/corepos/office/commands.py +++ b/rattail_corepos/corepos/office/commands.py @@ -96,6 +96,32 @@ class GetConfigValue(commands.Subcommand): self.stdout.write(f"{value}\n") +class ImportCSV(commands.ImportFileSubcommand): + """ + Import data from CSV to CORE Office "op" DB + """ + name = 'import-csv' + description = __doc__.strip() + handler_key = 'to_corepos_db_office_op.from_csv.import' + + def add_parser_args(self, parser): + super().add_parser_args(parser) + + parser.add_argument('--dbkey', metavar='KEY', default='default', + help="Config key for database engine to be used as the \"target\" " + "CORE DB, i.e. where data will be imported *to*. This key must be " + "defined in the [corepos.db.office_op] section of your config file.") + + def get_handler_kwargs(self, **kwargs): + kwargs = super().get_handler_kwargs(**kwargs) + + if 'args' in kwargs: + args = kwargs['args'] + kwargs['dbkey'] = args.dbkey + + return kwargs + + class ImportSelf(commands.ImportSubcommand): """ Import data from CORE Office ("op" DB) to "self" diff --git a/rattail_corepos/corepos/office/importing/db/csv.py b/rattail_corepos/corepos/office/importing/db/csv.py index 7222cb5..0486dcb 100644 --- a/rattail_corepos/corepos/office/importing/db/csv.py +++ b/rattail_corepos/corepos/office/importing/db/csv.py @@ -28,8 +28,7 @@ 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.office.importing.db.model import ToCore -from rattail_corepos.corepos.office.importing.db.corepos import ToCoreHandler +from rattail_corepos.corepos.office.importing.db.model import ToCoreHandler, ToCore class FromCSVToCore(FromCSVToSQLAlchemyMixin, FromFileHandler, ToCoreHandler): @@ -39,10 +38,6 @@ class FromCSVToCore(FromCSVToSQLAlchemyMixin, FromFileHandler, ToCoreHandler): host_title = "CSV" ToParent = ToCore - @property - def local_title(self): - return "CORE ({})".format(self.dbkey) - def get_model(self): return corepos diff --git a/rattail_corepos/emails.py b/rattail_corepos/emails.py index 5d7484a..b3be737 100644 --- a/rattail_corepos/emails.py +++ b/rattail_corepos/emails.py @@ -35,6 +35,14 @@ class core_office_export_lane_op_updates(ImporterEmail): abstract = False +class core_office_import_csv_updates(ImporterEmail): + """ + Sent when CSV -> CORE import involves data changes. + """ + handler_spec = 'rattail_corepos.corepos.office.importing.db.csv:FromCSVToCore' + abstract = False + + class corepos_problems_invalid_person_numbers(ProblemReportEmail): """ Looks for `custdata` records with invalid person number sequence. diff --git a/setup.cfg b/setup.cfg index a82b14a..0ca4969 100644 --- a/setup.cfg +++ b/setup.cfg @@ -42,6 +42,7 @@ console_scripts = core_office.commands = export-lane-op = rattail_corepos.corepos.office.commands:ExportLaneOp + import-csv = rattail_corepos.corepos.office.commands:ImportCSV import-self = rattail_corepos.corepos.office.commands:ImportSelf get-config-value = rattail_corepos.corepos.office.commands:GetConfigValue @@ -49,7 +50,7 @@ crepes.commands = export-core = rattail_corepos.corepos.commands:ExportCore export-csv = rattail_corepos.corepos.commands:ExportCSV import-core = rattail_corepos.corepos.commands:ImportCore - import-csv = rattail_corepos.corepos.commands:ImportCSV + import-csv = rattail_corepos.corepos.commands:LegacyImportCSV rattail.config.extensions = rattail-corepos = rattail_corepos.config:RattailCOREPOSExtension