Add support for per-item default discount, for new custorder

This commit is contained in:
Lance Edgar 2023-01-11 10:29:36 -06:00
parent dfa4178204
commit b8389c72bb
4 changed files with 72 additions and 8 deletions

View file

@ -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},