Expose per-item discounts for Trainwreck

This commit is contained in:
Lance Edgar 2022-02-19 17:31:14 -06:00
parent e990be3570
commit 7f06b3e53b
2 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,16 @@
## -*- coding: utf-8; -*-
<%inherit file="/master/view_row.mako" />
<%def name="modify_this_page_vars()">
${parent.modify_this_page_vars()}
<script type="text/javascript">
% if discounts_data is not Undefined:
${form.component_studly}Data.discountsData = ${json.dumps(discounts_data)|n}
% endif
</script>
</%def>
${parent.body()}

View file

@ -30,6 +30,8 @@ import six
from rattail.time import localtime from rattail.time import localtime
from webhelpers2.html import HTML
from tailbone.db import Session, TrainwreckSession, ExtraTrainwreckSessions from tailbone.db import Session, TrainwreckSession, ExtraTrainwreckSessions
from tailbone.views import MasterView from tailbone.views import MasterView
@ -136,9 +138,13 @@ class TransactionView(MasterView):
'description', 'description',
'unit_quantity', 'unit_quantity',
'subtotal', 'subtotal',
'discounts',
'discounted_subtotal',
'tax', 'tax',
'total', 'total',
'exempt_from_gross_sales', 'exempt_from_gross_sales',
'net_sales',
'gross_sales',
'void', 'void',
] ]
@ -231,6 +237,46 @@ class TransactionView(MasterView):
f.set_type('tax', 'currency') f.set_type('tax', 'currency')
f.set_type('total', 'currency') f.set_type('total', 'currency')
# discounts
f.set_renderer('discounts', self.render_discounts)
def render_discounts(self, item, field):
if not item.discounts:
return
route_prefix = self.get_route_prefix()
factory = self.get_grid_factory()
use_buefy = self.get_use_buefy()
g = factory(
key='{}.discounts'.format(route_prefix),
data=[] if use_buefy else item.discounts,
columns=['description', 'amount'],
request=self.request)
if use_buefy:
return HTML.literal(
g.render_buefy_table_element(data_prop='discountsData'))
else:
g.set_type('amount', 'currency')
return HTML.literal(g.render_grid())
def template_kwargs_view_row(self, **kwargs):
use_buefy = self.get_use_buefy()
if use_buefy:
app = self.get_rattail_app()
item = kwargs['instance']
discounts_data = []
for discount in item.discounts:
discounts_data.append({
'description': discount.description,
'amount': app.render_currency(discount.amount),
})
kwargs['discounts_data'] = discounts_data
return kwargs
def rollover(self): def rollover(self):
""" """
View for performing yearly rollover functions. View for performing yearly rollover functions.