-
-
+
+
%
@@ -1238,7 +1240,8 @@
% endif
% if allow_item_discounts:
- productDiscountPercent: null,
+ productDiscountPercent: ${json.dumps(default_item_discount)|n},
+ allowDiscountsIfOnSale: ${json.dumps(allow_item_discounts_if_on_sale)|n},
% endif
pendingProduct: {},
@@ -1421,6 +1424,19 @@
return text
},
+ % if allow_item_discounts:
+
+ allowItemDiscount() {
+ if (!this.allowDiscountsIfOnSale) {
+ if (this.productSalePriceDisplay) {
+ return false
+ }
+ }
+ return true
+ },
+
+ % endif
+
itemDialogSaveDisabled() {
if (this.itemDialogSaving) {
return true
@@ -1912,7 +1928,7 @@
% endif
% if allow_item_discounts:
- this.productDiscountPercent = null
+ this.productDiscountPercent = ${json.dumps(default_item_discount)|n}
% endif
this.itemDialogTabIndex = 0
@@ -2060,6 +2076,10 @@
this.productImageURL = null
this.productUnitChoices = this.defaultUnitChoices
+ % if allow_item_discounts:
+ this.productDiscountPercent = ${json.dumps(default_item_discount)|n}
+ % endif
+
% if product_price_may_be_questionable:
this.productPriceNeedsConfirmation = false
% endif
@@ -2106,6 +2126,11 @@
this.productSalePrice = response.data.sale_price
this.productSalePriceDisplay = response.data.sale_price_display
this.productSaleEndsDisplay = response.data.sale_ends_display
+
+ % if allow_item_discounts:
+ this.productDiscountPercent = this.allowItemDiscount ? response.data.default_item_discount : null
+ % endif
+
this.productURL = response.data.url
this.productImageURL = response.data.image_url
this.setProductUnitChoices(response.data.uom_choices)
diff --git a/tailbone/views/custorders/orders.py b/tailbone/views/custorders/orders.py
index 7d97b47f..8bc53a67 100644
--- a/tailbone/views/custorders/orders.py
+++ b/tailbone/views/custorders/orders.py
@@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
-# Copyright © 2010-2022 Lance Edgar
+# Copyright © 2010-2023 Lance Edgar
#
# This file is part of Rattail.
#
@@ -293,6 +293,7 @@ class CustomerOrderView(MasterView):
submits the order, at which point the batch is converted to a proper
order.
"""
+ app = self.get_rattail_app()
# TODO: deprecate / remove this
self.handler = self.batch_handler
batch = self.get_current_batch()
@@ -349,6 +350,10 @@ class CustomerOrderView(MasterView):
'default_uom_choices': self.batch_handler.uom_choices_for_product(None),
'default_uom': None,
'allow_item_discounts': self.batch_handler.allow_item_discounts(),
+ 'allow_item_discounts_if_on_sale': self.batch_handler.allow_item_discounts_if_on_sale(),
+ # nb. render quantity so that '10.0' => '10'
+ 'default_item_discount': app.render_quantity(
+ self.batch_handler.get_default_item_discount()),
'allow_past_item_reorder': self.batch_handler.allow_past_item_reorder(),
})
@@ -633,9 +638,11 @@ class CustomerOrderView(MasterView):
return {'error': six.text_type(error)}
else:
info['url'] = self.request.route_url('products.view', uuid=info['uuid'])
- return info
+ app = self.get_rattail_app()
+ return app.json_friendly(info)
def get_past_items(self, batch, data):
+ app = self.get_rattail_app()
past_products = self.batch_handler.get_past_products(batch)
past_items = []
@@ -646,6 +653,7 @@ class CustomerOrderView(MasterView):
# nb. handler may raise error if product is "unsupported"
pass
else:
+ item = app.json_friendly(item)
past_items.append(item)
return {'past_items': past_items}
@@ -987,6 +995,12 @@ class CustomerOrderView(MasterView):
{'section': 'rattail.custorders',
'option': 'allow_item_discounts',
'type': bool},
+ {'section': 'rattail.custorders',
+ 'option': 'allow_item_discounts_if_on_sale',
+ 'type': bool},
+ {'section': 'rattail.custorders',
+ 'option': 'default_item_discount',
+ 'type': float},
{'section': 'rattail.custorders',
'option': 'allow_past_item_reorder',
'type': bool},