Show link to txn as field when viewing trainwreck item

This commit is contained in:
Lance Edgar 2022-03-17 21:19:05 -05:00
parent c72d99794e
commit ab3a66542d

View file

@ -30,7 +30,7 @@ import six
from rattail.time import localtime from rattail.time import localtime
from webhelpers2.html import HTML from webhelpers2.html import HTML, tags
from tailbone.db import Session, TrainwreckSession, ExtraTrainwreckSessions from tailbone.db import Session, TrainwreckSession, ExtraTrainwreckSessions
from tailbone.views import MasterView from tailbone.views import MasterView
@ -128,6 +128,7 @@ class TransactionView(MasterView):
] ]
row_form_fields = [ row_form_fields = [
'transaction',
'sequence', 'sequence',
'item_type', 'item_type',
'item_scancode', 'item_scancode',
@ -271,9 +272,15 @@ class TransactionView(MasterView):
if row.void: if row.void:
return 'warning' return 'warning'
def get_row_instance_title(self, instance):
return "Trainwreck Line Item"
def configure_row_form(self, f): def configure_row_form(self, f):
super(TransactionView, self).configure_row_form(f) super(TransactionView, self).configure_row_form(f)
# transaction
f.set_renderer('transaction', self.render_transaction)
# quantity fields # quantity fields
f.set_type('unit_quantity', 'quantity') f.set_type('unit_quantity', 'quantity')
@ -287,6 +294,12 @@ class TransactionView(MasterView):
# discounts # discounts
f.set_renderer('discounts', self.render_discounts) f.set_renderer('discounts', self.render_discounts)
def render_transaction(self, item, field):
txn = getattr(item, field)
text = six.text_type(txn)
url = self.get_action_url('view', txn)
return tags.link_to(text, url)
def render_discounts(self, item, field): def render_discounts(self, item, field):
if not item.discounts: if not item.discounts:
return return