From d7462f415d741ab6686dbd2073d73eee62dada7d Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 14 Mar 2020 18:33:08 -0500 Subject: [PATCH] Add jump button, to view product in CORE Office --- rattail_demo/web/templates/products/view.mako | 27 +++++++++++++++++++ rattail_demo/web/views/products.py | 24 +++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 rattail_demo/web/templates/products/view.mako diff --git a/rattail_demo/web/templates/products/view.mako b/rattail_demo/web/templates/products/view.mako new file mode 100644 index 0000000..7aacafc --- /dev/null +++ b/rattail_demo/web/templates/products/view.mako @@ -0,0 +1,27 @@ +## -*- coding: utf-8; -*- +<%inherit file="tailbone:templates/products/view.mako" /> + +<%def name="object_helpers()"> + ${parent.object_helpers()} + ${self.render_xref_helper()} + + +<%def name="render_xref_helper()"> +
+

Cross-Reference

+
+ + View in CORE Office + +
+
+ + + +${parent.body()} diff --git a/rattail_demo/web/views/products.py b/rattail_demo/web/views/products.py index 0c0ba19..0dae70e 100644 --- a/rattail_demo/web/views/products.py +++ b/rattail_demo/web/views/products.py @@ -1,9 +1,9 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- """ Product views """ -from __future__ import unicode_literals, absolute_import +from rattail_corepos.config import core_office_url from tailbone.views import products as base @@ -55,6 +55,26 @@ class ProductsView(base.ProductsView): 'deleted', ] + def template_kwargs_view(self, **kwargs): + """ + Supplements the default logic as follows: + + Adds the URL for viewing the product within CORE Office, or else the + reason for lack of such a URL. + """ + kwargs = super(ProductsView, self).template_kwargs_view(**kwargs) + product = kwargs['instance'] + + # CORE Office URL + kwargs['core_office_url'] = None + office_url = core_office_url(self.rattail_config) + if not office_url: + kwargs['core_office_why_no_url'] = "CORE Office URL is not configured!" + else: + kwargs['core_office_url'] = '{}/item/ItemEditorPage.php?searchupc={}'.format(office_url, product.item_id) + + return kwargs + def includeme(config):