diff --git a/rattail_corepos/app.py b/rattail_corepos/app.py new file mode 100644 index 0000000..9f09683 --- /dev/null +++ b/rattail_corepos/app.py @@ -0,0 +1,106 @@ +# -*- coding: utf-8; -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2023 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 . +# +################################################################################ +""" +App Handler supplement +""" + +from rattail.app import RattailProvider, GenericHandler + + +class CoreProvider(RattailProvider): + """ + App provider for CORE-POS integration. + """ + + def get_corepos_handler(self, **kwargs): + if not hasattr(self, 'corepos_handler'): + spec = self.config.get('rattail', 'corepos.handler', + default='rattail_corepos.app:CoreHandler') + factory = self.load_object(spec) + self.corepos_handler = factory(self.config, **kwargs) + return self.corepos_handler + + +class CoreHandler(GenericHandler): + """ + Handler for CORE-POS integration. + """ + + def get_office_url( + self, + require=False, + **kwargs): + """ + Returns the base URL for the CORE Office web app. + """ + getter = self.config.require if require else self.config.get + url = getter('corepos', 'office.url') + if url: + return url.rstrip('/') + + def get_office_member_url( + self, + card_number, + office_url=None, + require=False, + **kwargs): + """ + Returns the CORE Office URL for the customer account with the + given card number. + """ + if not office_url: + office_url = self.get_office_url(require=require) + if office_url: + return f'{office_url}/mem/MemberEditor.php?memNum={card_number}' + + # TODO: deprecate / remove this + get_office_customer_account_url = get_office_member_url + + def get_office_product_url( + self, + upc, + office_url=None, + require=False, + **kwargs): + """ + Returns the CORE Office URL for the product with the given + UPC. + """ + if not office_url: + office_url = self.get_office_url(require=require) + if office_url: + return f'{office_url}/item/ItemEditorPage.php?searchupc={upc}' + + def get_office_vendor_url( + self, + id, + office_url=None, + require=False, + **kwargs): + """ + Returns the CORE Office URL for the vendor with the given ID. + """ + if not office_url: + office_url = self.get_office_url(require=require) + if office_url: + return f'{office_url}/item/vendors/VendorIndexPage.php?vid={id}' diff --git a/rattail_corepos/batch/equityimport.py b/rattail_corepos/batch/equityimport.py index ab0b60f..a109b1c 100644 --- a/rattail_corepos/batch/equityimport.py +++ b/rattail_corepos/batch/equityimport.py @@ -125,7 +125,6 @@ class CoreEquityImportBatchHandler(BatchHandler): def get_next_timestamp(self, row): dt = self.next_timestamp self.next_timestamp += datetime.timedelta(seconds=1) - # import ipdb; ipdb.set_trace() return self.app.localtime(dt, tzinfo=False).replace(microsecond=0) def get_transaction_status(self, row): diff --git a/rattail_corepos/config.py b/rattail_corepos/config.py index f6464e2..72c7cd1 100644 --- a/rattail_corepos/config.py +++ b/rattail_corepos/config.py @@ -183,26 +183,22 @@ class RattailCOREPOSExtension(ConfigExtension): def core_office_url(config, require=False, **kwargs): - """ - Returns the base URL for the CORE Office web app. Note that this URL will - *not* have a trailing slash. - """ - args = ['corepos', 'office.url'] - if require: - url = config.require(*args, **kwargs) - return url.rstrip('/') - else: - url = config.get(*args, **kwargs) - if url: - return url.rstrip('/') + """ DEPRECATED """ + warnings.warn("core_office_url() function is deprecated; please use " + "corepos_handler.get_office_url() instead", + DeprecationWarning, stacklevel=2) + + app = config.get_app() + corepos = app.get_corepos_handler() + return corepos.get_office_url(require=require, **kwargs) def core_office_customer_account_url(config, card_number, office_url=None): - """ - Returns the CORE Office URL for the customer account with the given card - number. - """ - if not office_url: - office_url = core_office_url(config, require=True) - return '{}/mem/MemberEditor.php?memNum={}'.format( - office_url, card_number) + """ DEPRECATED """ + warnings.warn("core_office_customer_account_url() function is deprecated; please use " + "corepos_handler.get_office_customer_account_url() instead", + DeprecationWarning, stacklevel=2) + + app = config.get_app() + corepos = app.get_corepos_handler() + return corepos.get_office_member_url(card_number, office_url=office_url, **kwargs) diff --git a/setup.cfg b/setup.cfg index a46cd4b..de606fb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -75,5 +75,8 @@ rattail.importing = to_corepos_db_lane_op.from_corepos_db_office_op.export = rattail_corepos.corepos.lane.importing.op.office:FromCoreOfficeToCoreLane to_trainwreck.from_corepos_db_office_trans = rattail_corepos.trainwreck.importing.corepos:FromCoreToTrainwreck +rattail.providers = + rattail_corepos = rattail_corepos.app:CoreProvider + trainwreck.commands = import-corepos = rattail_corepos.trainwreck.commands:ImportCore