Invoke handler for customer autocomplete when making new custorder

This commit is contained in:
Lance Edgar 2021-09-24 18:09:24 -04:00
parent 57cb787b30
commit 3b6b1aa5b6
4 changed files with 27 additions and 6 deletions

View file

@ -59,8 +59,11 @@ const TailboneAutocomplete = {
}, },
getDisplayText() { getDisplayText() {
if (this.assignedLabel) {
return this.assignedLabel
}
if (this.selected) { if (this.selected) {
return this.selected.label return this.selected.display || this.selected.label
} }
return "" return ""
}, },

View file

@ -80,7 +80,7 @@
<b-button v-if="assignedValue || selected" <b-button v-if="assignedValue || selected"
style="width: 100%; justify-content: left;" style="width: 100%; justify-content: left;"
@click="clearSelection()"> @click="clearSelection()">
{{ assignedLabel || selected.label }} (click to change) {{ getDisplayText() }} (click to change)
</b-button> </b-button>
</div> </div>

View file

@ -113,7 +113,7 @@
v-model="customerUUID" v-model="customerUUID"
placeholder="Enter name or phone number" placeholder="Enter name or phone number"
:initial-label="customerDisplay" :initial-label="customerDisplay"
serviceUrl="${url('customers.autocomplete')}" serviceUrl="${url('{}.customer_autocomplete'.format(route_prefix))}"
@input="customerChanged"> @input="customerChanged">
</tailbone-autocomplete> </tailbone-autocomplete>
</b-field> </b-field>

View file

@ -236,14 +236,14 @@ class CustomerOrderView(MasterView):
if self.handler.has_custom_product_autocomplete: if self.handler.has_custom_product_autocomplete:
route_prefix = self.get_route_prefix() route_prefix = self.get_route_prefix()
autocomplete = '{}.product_autocomplete'.format(route_prefix) product_autocomplete = '{}.product_autocomplete'.format(route_prefix)
else: else:
autocomplete = 'products.autocomplete' product_autocomplete = 'products.autocomplete'
context = {'batch': batch, context = {'batch': batch,
'normalized_batch': self.normalize_batch(batch), 'normalized_batch': self.normalize_batch(batch),
'order_items': items, 'order_items': items,
'product_autocomplete_url': self.request.route_url(autocomplete)} 'product_autocomplete_url': self.request.route_url(product_autocomplete)}
return self.render_to_response(template, context) return self.render_to_response(template, context)
def get_current_batch(self): def get_current_batch(self):
@ -296,6 +296,15 @@ class CustomerOrderView(MasterView):
url = self.request.route_url(route_prefix) url = self.request.route_url(route_prefix)
return self.redirect(url) return self.redirect(url)
def customer_autocomplete(self):
"""
Custom customer autocomplete logic, which invokes the handler.
"""
self.handler = self.get_batch_handler()
term = self.request.GET['term']
return self.handler.customer_autocomplete(self.Session(), term,
user=self.request.user)
def get_customer_info(self, batch, data): def get_customer_info(self, batch, data):
uuid = data.get('uuid') uuid = data.get('uuid')
if not uuid: if not uuid:
@ -583,6 +592,15 @@ class CustomerOrderView(MasterView):
route_prefix = cls.get_route_prefix() route_prefix = cls.get_route_prefix()
url_prefix = cls.get_url_prefix() url_prefix = cls.get_url_prefix()
# customer autocomplete
config.add_route('{}.customer_autocomplete'.format(route_prefix),
'{}/customer-autocomplete'.format(url_prefix),
request_method='GET')
config.add_view(cls, attr='customer_autocomplete',
route_name='{}.customer_autocomplete'.format(route_prefix),
renderer='json',
permission='customers.list')
# custom product autocomplete # custom product autocomplete
config.add_route('{}.product_autocomplete'.format(route_prefix), config.add_route('{}.product_autocomplete'.format(route_prefix),
'{}/product-autocomplete'.format(url_prefix), '{}/product-autocomplete'.format(url_prefix),