From 045940d4fa4afcdeae62fbf44d78d7219317e055 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Thu, 14 Sep 2023 12:59:39 -0500 Subject: [PATCH] Use handler to get CORE Office URLs instead of deprecated config function --- tailbone_corepos/menus.py | 6 ++-- tailbone_corepos/views/batch/coremember.py | 9 +++--- tailbone_corepos/views/batch/equityimport.py | 1 - tailbone_corepos/views/corepos/customers.py | 8 ++--- tailbone_corepos/views/corepos/master.py | 7 ++--- tailbone_corepos/views/corepos/members.py | 12 +++----- tailbone_corepos/views/customers.py | 9 ++---- tailbone_corepos/views/departments.py | 8 ++--- tailbone_corepos/views/members.py | 17 ++++++----- tailbone_corepos/views/people.py | 32 ++++++++++---------- tailbone_corepos/views/products.py | 10 +++--- tailbone_corepos/views/purchases.py | 19 ++++++------ tailbone_corepos/views/vendors.py | 10 +++--- 13 files changed, 66 insertions(+), 82 deletions(-) diff --git a/tailbone_corepos/menus.py b/tailbone_corepos/menus.py index ad7d6fc..a01a9ba 100644 --- a/tailbone_corepos/menus.py +++ b/tailbone_corepos/menus.py @@ -24,10 +24,9 @@ Common menus for CORE-POS """ -from rattail_corepos.config import core_office_url - def make_corepos_menu(request): + app = request.rattail_config.get_app() corepos_menu = { 'title': "CORE-POS", @@ -218,7 +217,8 @@ def make_corepos_menu(request): ], } - office_url = core_office_url(request.rattail_config) + corepos = app.get_corepos_handler() + office_url = corepos.get_office_url() if office_url: corepos_menu['items'].insert( 0, { diff --git a/tailbone_corepos/views/batch/coremember.py b/tailbone_corepos/views/batch/coremember.py index 2434d9c..0d36e67 100644 --- a/tailbone_corepos/views/batch/coremember.py +++ b/tailbone_corepos/views/batch/coremember.py @@ -28,7 +28,6 @@ from corepos.db.office_op import model as corepos from rattail_corepos.db.model import CoreMemberBatch, CoreMemberBatchRow from rattail_corepos.batch.coremember import CoreMemberBatchHandler -from rattail_corepos.config import core_office_url, core_office_customer_account_url from tailbone.views.batch import BatchMasterView from tailbone_corepos.db import CoreOfficeSession @@ -131,6 +130,7 @@ class CoreMemberBatchView(BatchMasterView): return 'notice' def template_kwargs_view_row(self, **kwargs): + app = self.get_rattail_app() batch = kwargs['parent_instance'] row = kwargs['instance'] kwargs['batch'] = batch @@ -149,13 +149,12 @@ class CoreMemberBatchView(BatchMasterView): # CORE Office URL kwargs['core_office_url'] = None if row.card_number: - office_url = core_office_url(self.rattail_config) + corepos = app.get_corepos_handler() + office_url = corepos.get_office_url() if not office_url: kwargs['core_office_why_no_url'] = "CORE Office URL is not configured" else: - url = core_office_customer_account_url(self.rattail_config, - row.card_number, - office_url=office_url) + url = corepos.get_office_member_url(row.card_number, office_url=office_url) if url: kwargs['core_office_url'] = url else: diff --git a/tailbone_corepos/views/batch/equityimport.py b/tailbone_corepos/views/batch/equityimport.py index f64e968..429c1e4 100644 --- a/tailbone_corepos/views/batch/equityimport.py +++ b/tailbone_corepos/views/batch/equityimport.py @@ -28,7 +28,6 @@ from corepos.db.office_op import model as corepos from rattail_corepos.db.model import CoreEquityImportBatch, CoreEquityImportBatchRow from rattail_corepos.batch.equityimport import CoreEquityImportBatchHandler -from rattail_corepos.config import core_office_url, core_office_customer_account_url from webhelpers2.html import tags diff --git a/tailbone_corepos/views/corepos/customers.py b/tailbone_corepos/views/corepos/customers.py index e2477e7..db87a0d 100644 --- a/tailbone_corepos/views/corepos/customers.py +++ b/tailbone_corepos/views/corepos/customers.py @@ -26,8 +26,6 @@ CORE POS customer views from corepos.db.office_op import model as corepos -from rattail_corepos.config import core_office_customer_account_url - from webhelpers2.html import tags from .master import CoreOfficeMasterView @@ -146,9 +144,9 @@ class CustomerClassicView(CoreOfficeMasterView): return render_member_info(self.request, custdata, field) def core_office_object_url(self, office_url, customer): - return core_office_customer_account_url(self.rattail_config, - customer.card_number, - office_url=office_url) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + return corepos.get_office_member_url(customer.card_number) def download_results_fields_available(self, **kwargs): fields = super().download_results_fields_available(**kwargs) diff --git a/tailbone_corepos/views/corepos/master.py b/tailbone_corepos/views/corepos/master.py index a524fec..11e8c62 100644 --- a/tailbone_corepos/views/corepos/master.py +++ b/tailbone_corepos/views/corepos/master.py @@ -26,9 +26,6 @@ CORE POS master view from collections import OrderedDict -from rattail.time import localtime -from rattail_corepos.config import core_office_url - from webhelpers2.html import tags from tailbone.views import MasterView @@ -114,11 +111,13 @@ class CoreMasterView(MasterView): the reason for lack of such a URL. """ kwargs = super().template_kwargs_view(**kwargs) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() obj = kwargs['instance'] # CORE Office URL kwargs['core_office_url'] = None - office_url = core_office_url(self.rattail_config) + office_url = corepos.get_office_url() if not office_url: kwargs['core_office_why_no_url'] = "CORE Office URL is not configured" else: diff --git a/tailbone_corepos/views/corepos/members.py b/tailbone_corepos/views/corepos/members.py index 5d81187..65730e7 100644 --- a/tailbone_corepos/views/corepos/members.py +++ b/tailbone_corepos/views/corepos/members.py @@ -29,8 +29,6 @@ from sqlalchemy import orm from corepos.db.office_op import model as corepos from corepos.db.office_trans import model as coretrans -from rattail_corepos.config import core_office_url, core_office_customer_account_url - from webhelpers2.html import HTML, tags from tailbone_corepos.db import CoreTransSession @@ -210,13 +208,11 @@ class MemberView(CoreOfficeMasterView): return app.render_currency(balance.payments) def get_xref_buttons(self, member): - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_member_url(member.card_number) if url: - url = core_office_customer_account_url(self.rattail_config, - member.card_number, - office_url=url) - return [self.make_xref_button(url=url, - text="View in CORE Office")] + return [self.make_xref_button(url=url, text="View in CORE Office")] def get_row_data(self, member): return CoreTransSession.query(coretrans.StockPurchase)\ diff --git a/tailbone_corepos/views/customers.py b/tailbone_corepos/views/customers.py index f23530f..0df630d 100644 --- a/tailbone_corepos/views/customers.py +++ b/tailbone_corepos/views/customers.py @@ -24,8 +24,6 @@ Customer Views """ -from rattail_corepos.config import core_office_url, core_office_customer_account_url - from webhelpers2.html import tags from tailbone.views import ViewSupplement @@ -61,11 +59,10 @@ class CustomerViewSupplement(ViewSupplement): return [model.CoreCustomer] def get_xref_buttons(self, customer): - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_member_url(customer.number) if url: - url = core_office_customer_account_url(self.rattail_config, - customer.number, - office_url=url) return [{'url': url, 'text': "View in CORE Office"}] def get_xref_links(self, customer): diff --git a/tailbone_corepos/views/departments.py b/tailbone_corepos/views/departments.py index 69f8f95..432b633 100644 --- a/tailbone_corepos/views/departments.py +++ b/tailbone_corepos/views/departments.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,8 +24,6 @@ Department Views """ -from rattail_corepos.config import core_office_url - from tailbone.views import ViewSupplement @@ -55,7 +53,9 @@ class DepartmentViewSupplement(ViewSupplement): return [model.CoreDepartment] def get_xref_buttons(self, department): - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_url() if url: url = '{}/item/departments/DepartmentEditor.php?did={}'.format( url, department.number) diff --git a/tailbone_corepos/views/members.py b/tailbone_corepos/views/members.py index 8678619..c428766 100644 --- a/tailbone_corepos/views/members.py +++ b/tailbone_corepos/views/members.py @@ -24,8 +24,6 @@ Member Views """ -from rattail_corepos.config import core_office_url, core_office_customer_account_url - from webhelpers2.html import tags from tailbone.views import ViewSupplement @@ -38,7 +36,9 @@ class MembershipTypeViewSupplement(ViewSupplement): route_prefix = 'membership_types' def get_xref_buttons(self, memtype): - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_url() if url: url = f'{url}/mem/MemberTypeEditor.php' return [{'url': url, 'text': "View in CORE Office"}] @@ -71,11 +71,10 @@ class MemberViewSupplement(ViewSupplement): def get_xref_buttons(self, member): if member.customer and member.customer.corepos_card_number: - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_member_url(member.customer.corepos_card_number) if url: - url = core_office_customer_account_url(self.rattail_config, - member.customer.corepos_card_number, - office_url=url) return [{'url': url, 'text': "View in CORE Office"}] def get_xref_links(self, member): @@ -140,7 +139,9 @@ class MemberEquityPaymentViewSupplement(ViewSupplement): def get_xref_buttons(self, payment): if payment.corepos_transaction_number and payment.corepos_card_number: - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_url() if url: url = f'{url}/reports/Equity/EquityReport.php?memNum={payment.corepos_card_number}' return [{'url': url, 'text': "View in CORE Office"}] diff --git a/tailbone_corepos/views/people.py b/tailbone_corepos/views/people.py index f996aef..3e802d7 100644 --- a/tailbone_corepos/views/people.py +++ b/tailbone_corepos/views/people.py @@ -26,8 +26,6 @@ Person views from collections import OrderedDict -from rattail_corepos.config import core_office_customer_account_url - from tailbone.views import ViewSupplement @@ -60,8 +58,9 @@ class PersonViewSupplement(ViewSupplement): def get_context_for_customer(self, customer, context): if customer.corepos_card_number: - url = core_office_customer_account_url(self.rattail_config, - customer.corepos_card_number) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_member_url(customer.corepos_card_number) if url: context['external_links'].append({'label': "View in CORE Office", 'url': url}) @@ -70,20 +69,21 @@ class PersonViewSupplement(ViewSupplement): def get_member_xref_buttons(self, person): buttons = OrderedDict() + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + office_url = corepos.get_office_url() + if office_url: + kw = {'office_url': office_url} - for member in person.members: - url = core_office_customer_account_url( - self.rattail_config, member.number) - buttons[member.uuid] = {'url': url, - 'text': "View in CORE Office"} + for member in person.members: + url = corepos.get_office_member_url(member.number, **kw) + buttons[member.uuid] = {'url': url, 'text': "View in CORE Office"} - for customer in person.customers: - for member in customer.members: - if member.uuid not in buttons: - url = core_office_customer_account_url( - self.rattail_config, member.number) - buttons[member.uuid] = {'url': url, - 'text': "View in CORE Office"} + for customer in person.customers: + for member in customer.members: + if member.uuid not in buttons: + url = corepos.get_office_member_url(member.number, **kw) + buttons[member.uuid] = {'url': url, 'text': "View in CORE Office"} return buttons.values() diff --git a/tailbone_corepos/views/products.py b/tailbone_corepos/views/products.py index 2797f1c..4ff4079 100644 --- a/tailbone_corepos/views/products.py +++ b/tailbone_corepos/views/products.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,8 +24,6 @@ Product Views """ -from rattail_corepos.config import core_office_url - from webhelpers2.html import tags from tailbone.views import ViewSupplement @@ -74,10 +72,10 @@ class ProductViewSupplement(ViewSupplement): return ['corepos_id'] def get_xref_buttons(self, product): - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_product_url(product.item_id) if url: - url = '{}/item/ItemEditorPage.php?searchupc={}'.format( - url, product.item_id) return [{'url': url, 'text': "View in CORE Office"}] def get_xref_links(self, product): diff --git a/tailbone_corepos/views/purchases.py b/tailbone_corepos/views/purchases.py index 2fee28e..1337a88 100644 --- a/tailbone_corepos/views/purchases.py +++ b/tailbone_corepos/views/purchases.py @@ -27,9 +27,6 @@ Purchase views import csv import os -from rattail.util import pretty_quantity -from rattail_corepos.config import core_office_url - from tailbone.views.purchases import core as base @@ -39,11 +36,13 @@ class PurchaseView(base.PurchaseView): """ def template_kwargs_view(self, **kwargs): - kwargs = super(PurchaseView, self).template_kwargs_view(**kwargs) + kwargs = super().template_kwargs_view(**kwargs) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() - url = core_office_url(self.rattail_config) + url = corepos.get_office_url() if url: - url = '{}/purchasing/ImportPurchaseOrder.php'.format(url) + url = f'{url}/purchasing/ImportPurchaseOrder.php' kwargs['corepos_import_url'] = url return kwargs @@ -83,13 +82,13 @@ class PurchaseView(base.PurchaseView): # for now i am being "conservative" and mimicking CORE *behavior*. unit_size = None if item.product: - unit_size = pretty_quantity(item.product.unit_size) + unit_size = app.render_quantity(item.product.unit_size) rows.append({ 'sku': item.vendor_code, 'cost_total': item.po_total, - 'quantity_units': pretty_quantity(item.units_ordered), - 'quantity_cases': pretty_quantity(item.cases_ordered), - 'units_per_case': pretty_quantity(item.case_quantity), + 'quantity_units': app.render_quantity(item.units_ordered), + 'quantity_cases': app.render_quantity(item.cases_ordered), + 'units_per_case': app.render_quantity(item.case_quantity), 'unit_size': unit_size, 'brand': item.brand_name, 'description': item.description, diff --git a/tailbone_corepos/views/vendors.py b/tailbone_corepos/views/vendors.py index 585ca6d..7eaedb2 100644 --- a/tailbone_corepos/views/vendors.py +++ b/tailbone_corepos/views/vendors.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2022 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -24,8 +24,6 @@ Vendor views """ -from rattail_corepos.config import core_office_url - from tailbone.views import ViewSupplement @@ -55,10 +53,10 @@ class VendorViewSupplement(ViewSupplement): return [model.CoreVendor] def get_xref_buttons(self, vendor): - url = core_office_url(self.rattail_config) + app = self.get_rattail_app() + corepos = app.get_corepos_handler() + url = corepos.get_office_vendor_url(vendor.corepos_id) if url: - url = '{}/item/vendors/VendorIndexPage.php?vid={}'.format( - url, vendor.corepos_id) return [{'url': url, 'text': "View in CORE Office"}]