Use handler to get CORE Office URLs

instead of deprecated config function
This commit is contained in:
Lance Edgar 2023-09-14 12:59:39 -05:00
parent 0b7f3d8dcc
commit 045940d4fa
13 changed files with 66 additions and 82 deletions

View file

@ -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, {

View file

@ -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:

View file

@ -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

View file

@ -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)

View file

@ -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:

View file

@ -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)\

View file

@ -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):

View file

@ -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)

View file

@ -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"}]

View file

@ -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"}
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"}
url = corepos.get_office_member_url(member.number, **kw)
buttons[member.uuid] = {'url': url, 'text': "View in CORE Office"}
return buttons.values()

View file

@ -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):

View file

@ -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,

View file

@ -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"}]