Add core-office import-csv command; deprecate crepes import-csv
				
					
				
			This commit is contained in:
		
							parent
							
								
									6267205966
								
							
						
					
					
						commit
						2cf865d879
					
				
					 5 changed files with 46 additions and 31 deletions
				
			
		|  | @ -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) | ||||
|  |  | |||
|  | @ -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" | ||||
|  |  | |||
|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -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. | ||||
|  |  | |||
|  | @ -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 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar