From 031d97aea303628f9baba740ddd998553327f958 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 1 Mar 2022 13:01:59 -0600 Subject: [PATCH] Avoid making discounts data if missing field, for trainwreck item view --- tailbone/views/trainwreck/base.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/tailbone/views/trainwreck/base.py b/tailbone/views/trainwreck/base.py index 081e7119..8a610104 100644 --- a/tailbone/views/trainwreck/base.py +++ b/tailbone/views/trainwreck/base.py @@ -268,17 +268,19 @@ class TransactionView(MasterView): def template_kwargs_view_row(self, **kwargs): use_buefy = self.get_use_buefy() if use_buefy: + form = kwargs['form'] + if 'discounts' in form: - app = self.get_rattail_app() - item = kwargs['instance'] - discounts_data = [] - for discount in item.discounts: - discounts_data.append({ - 'discount_type': discount.discount_type, - 'description': discount.description, - 'amount': app.render_currency(discount.amount), - }) - kwargs['discounts_data'] = discounts_data + app = self.get_rattail_app() + item = kwargs['instance'] + discounts_data = [] + for discount in item.discounts: + discounts_data.append({ + 'discount_type': discount.discount_type, + 'description': discount.description, + 'amount': app.render_currency(discount.amount), + }) + kwargs['discounts_data'] = discounts_data return kwargs