From 1bdb845032edae646bf3f3be5df462f562f5aa63 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Wed, 3 Nov 2021 20:20:22 -0500 Subject: [PATCH] Honor the "product price may be questionable" flag for new custorder i.e. don't expose the per-item flag unless *that* flag is set --- tailbone/templates/custorders/create.mako | 27 ++++++++++++++++++++++- tailbone/views/custorders/orders.py | 22 ++++++++++++++---- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/tailbone/templates/custorders/create.mako b/tailbone/templates/custorders/create.mako index c6bcbd64..7d368bdf 100644 --- a/tailbone/templates/custorders/create.mako +++ b/tailbone/templates/custorders/create.mako @@ -545,12 +545,14 @@ + % if product_price_may_be_questionable: This price is questionable and should be confirmed by someone before order proceeds. + % endif @@ -629,7 +631,11 @@ - + {{ props.row.total_price_display }} @@ -758,7 +764,10 @@ defaultUOM: defaultUOM, productUOM: defaultUOM, productCaseSize: null, + + % if product_price_may_be_questionable: productPriceNeedsConfirmation: false, + % endif ## TODO: should find a better way to handle CSRF token csrftoken: ${json.dumps(request.session.get_csrf_token() or request.session.new_csrf_token())|n}, @@ -1290,7 +1299,11 @@ this.productQuantity = 1 this.productUnitChoices = this.defaultUnitChoices this.productUOM = this.defaultUOM + + % if product_price_may_be_questionable: this.productPriceNeedsConfirmation = false + % endif + this.showingItemDialog = true this.$nextTick(() => { this.$refs.productAutocomplete.focus() @@ -1311,7 +1324,10 @@ this.productQuantity = row.order_quantity this.productUnitChoices = row.order_uom_choices this.productUOM = row.order_uom + + % if product_price_may_be_questionable: this.productPriceNeedsConfirmation = row.price_needs_confirmation + % endif this.showingItemDialog = true }, @@ -1348,7 +1364,10 @@ this.productURL = null this.productImageURL = null this.productUnitChoices = this.defaultUnitChoices + + % if product_price_may_be_questionable: this.productPriceNeedsConfirmation = false + % endif }, setProductUnitChoices(choices) { @@ -1387,7 +1406,10 @@ this.productURL = response.data.url this.productImageURL = response.data.image_url this.setProductUnitChoices(response.data.uom_choices) + + % if product_price_may_be_questionable: this.productPriceNeedsConfirmation = false + % endif }) } else { this.clearProduct() @@ -1401,7 +1423,10 @@ product_uuid: this.productUUID, order_quantity: this.productQuantity, order_uom: this.productUOM, + + % if product_price_may_be_questionable: price_needs_confirmation: this.productPriceNeedsConfirmation, + % endif } if (this.editingItem) { diff --git a/tailbone/views/custorders/orders.py b/tailbone/views/custorders/orders.py index ce74bac2..b3d44183 100644 --- a/tailbone/views/custorders/orders.py +++ b/tailbone/views/custorders/orders.py @@ -188,7 +188,11 @@ class CustomerOrderView(MasterView): g.set_type('order_quantity', 'quantity') g.set_type('cases_ordered', 'quantity') g.set_type('units_ordered', 'quantity') - g.set_renderer('total_price', self.render_price_with_confirmation) + + if self.handler.product_price_may_be_questionable(): + g.set_renderer('total_price', self.render_price_with_confirmation) + else: + g.set_type('total_price', 'currency') g.set_enum('order_uom', self.enum.UNIT_OF_MEASURE) g.set_renderer('status_code', self.render_row_status_code) @@ -277,6 +281,7 @@ class CustomerOrderView(MasterView): 'batch': batch, 'normalized_batch': self.normalize_batch(batch), 'new_order_requires_customer': self.handler.new_order_requires_customer(), + 'product_price_may_be_questionable': self.handler.product_price_may_be_questionable(), 'allow_contact_info_choice': self.handler.allow_contact_info_choice(), 'restrict_contact_info': self.handler.should_restrict_contact_info(), 'order_items': items, @@ -615,12 +620,14 @@ class CustomerOrderView(MasterView): 'unit_price_display': self.get_unit_price_display(row), 'total_price': six.text_type(row.total_price) if row.total_price is not None else None, 'total_price_display': "${:0.2f}".format(row.total_price) if row.total_price is not None else None, - 'price_needs_confirmation': row.price_needs_confirmation, 'status_code': row.status_code, 'status_text': row.status_text, } + if self.handler.product_price_may_be_questionable(): + data['price_needs_confirmation'] = row.price_needs_confirmation + key = self.rattail_config.product_key() if key == 'upc': data['product_key'] = data['product_upc_pretty'] @@ -669,10 +676,14 @@ class CustomerOrderView(MasterView): if not product: return {'error': "Product not found"} + kwargs = {} + if self.handler.product_price_may_be_questionable(): + kwargs['price_needs_confirmation'] = data.get('price_needs_confirmation') + row = self.handler.add_product(batch, product, decimal.Decimal(data.get('order_quantity') or '0'), data.get('order_uom'), - price_needs_confirmation=data.get('price_needs_confirmation')) + **kwargs) self.Session.flush() else: # product is not known @@ -707,7 +718,10 @@ class CustomerOrderView(MasterView): row.product = product row.order_quantity = decimal.Decimal(data.get('order_quantity') or '0') row.order_uom = data.get('order_uom') - row.price_needs_confirmation = data.get('price_needs_confirmation') + + if self.handler.product_price_may_be_questionable(): + row.price_needs_confirmation = data.get('price_needs_confirmation') + self.handler.refresh_row(row) self.Session.flush() self.Session.refresh(row)