Expose per-item discounts for Trainwreck
This commit is contained in:
parent
e990be3570
commit
7f06b3e53b
16
tailbone/templates/trainwreck/transactions/view_row.mako
Normal file
16
tailbone/templates/trainwreck/transactions/view_row.mako
Normal 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()}
|
|
@ -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.
|
||||||
|
|
Loading…
Reference in a new issue