Add common base for commands which import straight to CORE op/trans DB
This commit is contained in:
		
							parent
							
								
									f6ca488c66
								
							
						
					
					
						commit
						465322b87b
					
				
					 2 changed files with 52 additions and 4 deletions
				
			
		|  | @ -111,6 +111,32 @@ class Anonymize(commands.Subcommand): | |||
|                            message="Anonymizing all member data") | ||||
| 
 | ||||
| 
 | ||||
| class CoreDBImportSubcommand(commands.ImportSubcommand): | ||||
|     """ | ||||
|     Base class for commands which import straight to CORE DB | ||||
|     """ | ||||
| 
 | ||||
|     def add_parser_args(self, parser): | ||||
|         super().add_parser_args(parser) | ||||
| 
 | ||||
|         parser.add_argument('--corepos-dbtype', metavar='TYPE', default='office_op', | ||||
|                             choices=['office_op', 'office_trans'], | ||||
|                             help="Config *type* for CORE-POS database engine to which data " | ||||
|                             "should be written.  Default type is 'office_op' - this determines " | ||||
|                             "which config section is used with regard to the --corepos-dbkey arg.") | ||||
| 
 | ||||
|         parser.add_argument('--corepos-dbkey', metavar='KEY', default='default', | ||||
|                             help="Config key for CORE-POS database engine to which data should " | ||||
|                             "be written.  This key must be defined in the config section as " | ||||
|                             "determiend by the --corpos-dbtype arg.") | ||||
| 
 | ||||
|     def get_handler_kwargs(self, **kwargs): | ||||
|         if 'args' in kwargs: | ||||
|             kwargs['corepos_dbtype'] = kwargs['args'].corepos_dbtype | ||||
|             kwargs['corepos_dbkey'] = kwargs['args'].corepos_dbkey | ||||
|         return kwargs | ||||
| 
 | ||||
| 
 | ||||
| class ExportLaneOp(commands.ImportSubcommand): | ||||
|     """ | ||||
|     Export "op" data from CORE Office to CORE Lane | ||||
|  |  | |||
|  | @ -34,7 +34,7 @@ CORE-POS model importers (direct DB) | |||
| import logging | ||||
| 
 | ||||
| from corepos.db.office_op import model as corepos, Session as CoreSession | ||||
| from corepos.db.office_trans import model as coretrans | ||||
| from corepos.db.office_trans import model as coretrans, Session as CoreTransSession | ||||
| 
 | ||||
| from rattail import importing | ||||
| from rattail.importing.handlers import ToSQLAlchemyHandler | ||||
|  | @ -47,12 +47,27 @@ class ToCoreHandler(ToSQLAlchemyHandler): | |||
|     """ | ||||
|     Base class for import handlers which target a CORE database on the local side. | ||||
|     """ | ||||
|     generic_local_title = 'CORE Office (DB "op")' | ||||
|     local_title = 'CORE Office (DB "op")' | ||||
|     # TODO: should change local_key in all apps! since dbtype can vary now | ||||
|     local_key = 'corepos_db_office_op' | ||||
|     generic_local_title = "CORE Office (DB)" | ||||
|     corepos_dbtype = 'office_op' | ||||
|     corepos_dbkey = 'default' | ||||
| 
 | ||||
|     @property | ||||
|     def local_title(self): | ||||
|         dbtype = 'op' | ||||
|         if self.corepos_dbtype == 'office_trans': | ||||
|             dbtype = 'trans' | ||||
|         return f"CORE Office (DB '{dbtype}')" | ||||
| 
 | ||||
|     def make_session(self): | ||||
|         return CoreSession() | ||||
| 
 | ||||
|         # session type depends on the --corepos-dbtype arg | ||||
|         if self.corepos_dbtype == 'office_trans': | ||||
|             return CoreTransSession(bind=self.config.coretrans_engines[self.corepos_dbkey]) | ||||
| 
 | ||||
|         # assume office_op by default | ||||
|         return CoreSession(bind=self.config.corepos_engines[self.corepos_dbkey]) | ||||
| 
 | ||||
| 
 | ||||
| class ToCore(importing.ToSQLAlchemy): | ||||
|  | @ -270,6 +285,13 @@ class HouseCouponImporter(ToCore): | |||
| # CORE Transactions | ||||
| ######################################## | ||||
| 
 | ||||
| class StockPurchaseImporter(ToCoreTrans): | ||||
|     """ | ||||
|     CORE-POS stock purchase data importer. | ||||
|     """ | ||||
|     model_class = coretrans.StockPurchase | ||||
| 
 | ||||
| 
 | ||||
| class TransactionDetailImporter(ToCoreTrans): | ||||
|     """ | ||||
|     CORE-POS transaction data importer. | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Lance Edgar
						Lance Edgar