Add/improve some CORE member xref links

This commit is contained in:
Lance Edgar 2023-06-06 09:51:17 -05:00
parent fcaa486e7f
commit 8e45b3fbf4
6 changed files with 72 additions and 13 deletions

View file

@ -1,3 +0,0 @@
## -*- coding: utf-8; -*-
<%inherit file="/core-pos/master/view.mako" />
${parent.body()}

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.
#
@ -48,6 +48,7 @@ class CustomerView(CoreOfficeMasterView):
Base class for customer views.
"""
model_class = corepos.CustData
model_key = ('card_number', 'person_number')
model_title = "CORE-POS Customer (Legacy)"
model_title_plural = "CORE-POS Customers (Legacy)"
url_prefix = '/core-pos/customers'

View file

@ -92,6 +92,7 @@ class CoreMasterView(MasterView):
Adds the URL for viewing the record/object within CORE Office, or else
the reason for lack of such a URL.
"""
kwargs = super().template_kwargs_view(**kwargs)
obj = kwargs['instance']
# CORE Office URL

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.
#
@ -26,7 +26,7 @@ CORE-POS member views
from corepos.db.office_op import model as corepos
from rattail_corepos.config import core_office_customer_account_url
from rattail_corepos.config import core_office_url, core_office_customer_account_url
from webhelpers2.html import HTML, tags
@ -159,7 +159,9 @@ class MemberView(CoreOfficeMasterView):
items = []
for customer in customers:
text = str(customer)
url = self.request.route_url('corepos.customers.view', id=customer.id)
url = self.request.route_url('corepos.customers.view',
card_number=customer.card_number,
person_number=customer.person_number)
link = tags.link_to(text, url)
items.append(HTML.tag('li', c=[link]))
return HTML.tag('ul', c=items)
@ -174,10 +176,14 @@ class MemberView(CoreOfficeMasterView):
card_number=suspension.card_number)
return tags.link_to(text, url)
def core_office_object_url(self, office_url, member):
return core_office_customer_account_url(self.rattail_config,
member.card_number,
office_url=office_url)
def get_xref_buttons(self, member):
url = core_office_url(self.rattail_config)
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")]
def defaults(config, **kwargs):

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,6 +24,10 @@
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
@ -35,6 +39,7 @@ class CustomerViewSupplement(ViewSupplement):
labels = {
'corepos_account_id': "CORE-POS Account ID",
'corepos_card_number': "CORE-POS Card Number",
}
def get_grid_query(self, query):
@ -44,15 +49,31 @@ class CustomerViewSupplement(ViewSupplement):
def configure_grid(self, g):
model = self.model
g.set_filter('corepos_account_id', model.CoreCustomer.corepos_account_id)
g.set_filter('corepos_card_number', model.CoreCustomer.corepos_card_number)
def configure_form(self, f):
if not self.master.creating:
f.append('corepos_account_id')
f.append('corepos_card_number')
def get_version_child_classes(self):
model = self.model
return [model.CoreCustomer]
def get_xref_buttons(self, customer):
url = core_office_url(self.rattail_config)
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):
if customer.corepos_card_number:
url = self.request.route_url('corepos.members.view',
card_number=customer.corepos_card_number)
return [tags.link_to("View CORE-POS Member", url)]
def includeme(config):
CustomerViewSupplement.defaults(config)

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,9 +24,26 @@
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
class MembershipTypeViewSupplement(ViewSupplement):
"""
MembershipType view supplement for CORE integration
"""
route_prefix = 'membership_types'
def get_xref_buttons(self, memtype):
url = core_office_url(self.rattail_config)
if url:
url = f'{url}/mem/MemberTypeEditor.php'
return [{'url': url, 'text': "View in CORE Office"}]
class MemberViewSupplement(ViewSupplement):
"""
Member view supplement for CORE integration
@ -52,6 +69,22 @@ class MemberViewSupplement(ViewSupplement):
model = self.model
return [model.CoreMember]
def get_xref_buttons(self, member):
if member.customer and member.customer.corepos_card_number:
url = core_office_url(self.rattail_config)
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):
if member.customer and member.customer.corepos_card_number:
url = self.request.route_url('corepos.members.view',
card_number=member.customer.corepos_card_number)
return [tags.link_to("View CORE-POS Member", url)]
def includeme(config):
MembershipTypeViewSupplement.defaults(config)
MemberViewSupplement.defaults(config)