Move some custorder logic to handler; allow force-swap of product selection

This commit is contained in:
Lance Edgar 2021-11-03 19:19:20 -05:00
parent b0fa559760
commit 4d33e3dcbe
3 changed files with 24 additions and 60 deletions

View file

@ -32,10 +32,17 @@ const TailboneAutocomplete = {
// allows for the "label" to display correctly as well // allows for the "label" to display correctly as well
initialLabel: String, initialLabel: String,
// TODO: i am not sure this is needed? but current logic does // while the `initialLabel` above is useful for setting the
// handle it specially, so am leaving for now. if this prop // *initial* label (of course), it cannot be used to
// is set by the caller, then the `assignedLabel` will *always* // arbitrarily update the label during the component's life.
// be shown for the button (when "selection" has been made) // if you do need to *update* the label after initial page
// load, then you should set `assignedLabel` instead. one
// place this happens is in /custorders/create page, where
// product autocomplete shows some results, and user clicks
// one, but then handler logic can forcibly "swap" the
// selection, causing *different* product data to come back
// from the server, and autocomplete label should be updated
// to match. this feels a bit awkward still but does work..
assignedLabel: String, assignedLabel: String,
// simple placeholder text for the input box // simple placeholder text for the input box

View file

@ -511,7 +511,7 @@
<tailbone-autocomplete ref="productAutocomplete" <tailbone-autocomplete ref="productAutocomplete"
v-model="productUUID" v-model="productUUID"
placeholder="Enter UPC or brand, description etc." placeholder="Enter UPC or brand, description etc."
:initial-label="productDisplay" :assigned-label="productDisplay"
serviceUrl="${url('{}.product_autocomplete'.format(route_prefix))}" serviceUrl="${url('{}.product_autocomplete'.format(route_prefix))}"
@input="productChanged"> @input="productChanged">
</tailbone-autocomplete> </tailbone-autocomplete>
@ -1368,12 +1368,18 @@
productChanged(uuid) { productChanged(uuid) {
if (uuid) { if (uuid) {
this.productUUID = uuid
let params = { let params = {
action: 'get_product_info', action: 'get_product_info',
uuid: this.productUUID, uuid: uuid,
} }
// nb. it is possible for the handler to "swap"
// the product selection, i.e. user chooses a "per
// LB" item but the handler only allows selling by
// the "case" item. so we do not assume the uuid
// received above is the correct one, but just use
// whatever came back from handler
this.submitBatchData(params, response => { this.submitBatchData(params, response => {
this.productUUID = response.data.uuid
this.productUPC = response.data.upc_pretty this.productUPC = response.data.upc_pretty
this.productKey = response.data.key this.productKey = response.data.key
this.productDisplay = response.data.full_description this.productDisplay = response.data.full_description

View file

@ -551,61 +551,12 @@ class CustomerOrderView(MasterView):
return self.info_for_product(batch, data, product) return self.info_for_product(batch, data, product)
def uom_choices_for_product(self, product): def uom_choices_for_product(self, product):
choices = [] return self.handler.uom_choices_for_product(product)
# Each
if not product or not product.weighed:
unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_EACH]
choices.append({'key': self.enum.UNIT_OF_MEASURE_EACH,
'value': unit_name})
# Pound
if not product or product.weighed:
unit_name = self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_POUND]
choices.append({
'key': self.enum.UNIT_OF_MEASURE_POUND,
'value': unit_name,
})
# Case
case_text = None
case_size = self.handler.get_case_size_for_product(product)
if case_size is None:
case_text = "{} (&times; ?? {})".format(
self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE],
unit_name)
elif case_size > 1:
case_text = "{} (&times; {} {})".format(
self.enum.UNIT_OF_MEASURE[self.enum.UNIT_OF_MEASURE_CASE],
pretty_quantity(case_size),
unit_name)
if case_text:
choices.append({'key': self.enum.UNIT_OF_MEASURE_CASE,
'value': case_text})
return choices
def info_for_product(self, batch, data, product): def info_for_product(self, batch, data, product):
app = self.get_rattail_app() info = self.handler.get_product_info(batch, product)
products = app.get_products_handler() info['url'] = self.request.route_url('products.view', uuid=info['uuid'])
data = { return info
'uuid': product.uuid,
'upc': six.text_type(product.upc),
'upc_pretty': product.upc.pretty(),
'unit_price_display': self.get_unit_price_display(product),
'full_description': product.full_description,
'url': self.request.route_url('products.view', uuid=product.uuid),
'image_url': products.get_image_url(product),
'uom_choices': self.uom_choices_for_product(product),
}
key = self.rattail_config.product_key()
if key == 'upc':
data['key'] = data['upc_pretty']
else:
data['key'] = getattr(product, key, data['upc_pretty'])
return data
def normalize_batch(self, batch): def normalize_batch(self, batch):
return { return {