Add way to customize product autocomplete for new custorder
This commit is contained in:
parent
177286533d
commit
25c1ae3c41
|
@ -207,7 +207,7 @@
|
|||
v-model="productUUID"
|
||||
:assigned-value="productUUID"
|
||||
:assigned-label="productDisplay"
|
||||
serviceUrl="${url('products.autocomplete')}"
|
||||
serviceUrl="${product_autocomplete_url}"
|
||||
@input="productChanged">
|
||||
</tailbone-autocomplete>
|
||||
</b-field>
|
||||
|
|
|
@ -123,6 +123,11 @@ class CustomerOrderView(MasterView):
|
|||
url = self.request.route_url('people.view', uuid=person.uuid)
|
||||
return tags.link_to(text, url)
|
||||
|
||||
def get_batch_handler(self):
|
||||
return get_batch_handler(
|
||||
self.rattail_config, 'custorder',
|
||||
default='rattail.batch.custorder:CustomerOrderBatchHandler')
|
||||
|
||||
def create(self, form=None, template='create'):
|
||||
"""
|
||||
View for creating a new customer order. Note that it does so by way of
|
||||
|
@ -130,10 +135,7 @@ class CustomerOrderView(MasterView):
|
|||
submits the order, at which point the batch is converted to a proper
|
||||
order.
|
||||
"""
|
||||
self.handler = get_batch_handler(
|
||||
self.rattail_config, 'custorder',
|
||||
default='rattail.batch.custorder:CustomerOrderBatchHandler')
|
||||
|
||||
self.handler = self.get_batch_handler()
|
||||
batch = self.get_current_batch()
|
||||
|
||||
if self.request.method == 'POST':
|
||||
|
@ -166,9 +168,17 @@ class CustomerOrderView(MasterView):
|
|||
|
||||
items = [self.normalize_row(row)
|
||||
for row in batch.active_rows()]
|
||||
|
||||
if self.handler.has_custom_product_autocomplete:
|
||||
route_prefix = self.get_route_prefix()
|
||||
autocomplete = '{}.product_autocomplete'.format(route_prefix)
|
||||
else:
|
||||
autocomplete = 'products.autocomplete'
|
||||
|
||||
context = {'batch': batch,
|
||||
'normalized_batch': self.normalize_batch(batch),
|
||||
'order_items': items}
|
||||
'order_items': items,
|
||||
'product_autocomplete_url': self.request.route_url(autocomplete)}
|
||||
return self.render_to_response(template, context)
|
||||
|
||||
def get_current_batch(self):
|
||||
|
@ -258,6 +268,15 @@ class CustomerOrderView(MasterView):
|
|||
self.Session.flush()
|
||||
return {'success': True}
|
||||
|
||||
def product_autocomplete(self):
|
||||
"""
|
||||
Custom product autocomplete logic, which invokes the handler.
|
||||
"""
|
||||
self.handler = self.get_batch_handler()
|
||||
term = self.request.GET['term']
|
||||
return self.handler.custom_product_autocomplete(self.Session(), term,
|
||||
user=self.request.user)
|
||||
|
||||
def find_product_by_upc(self, batch, data):
|
||||
upc = data.get('upc')
|
||||
if not upc:
|
||||
|
@ -489,6 +508,26 @@ class CustomerOrderView(MasterView):
|
|||
def execute_new_order_batch(self, batch, data):
|
||||
return self.handler.do_execute(batch, self.request.user)
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
cls._order_defaults(config)
|
||||
cls._defaults(config)
|
||||
|
||||
@classmethod
|
||||
def _order_defaults(cls, config):
|
||||
route_prefix = cls.get_route_prefix()
|
||||
url_prefix = cls.get_url_prefix()
|
||||
|
||||
# custom product autocomplete
|
||||
config.add_route('{}.product_autocomplete'.format(route_prefix),
|
||||
'{}/product-autocomplete'.format(url_prefix),
|
||||
request_method='GET')
|
||||
config.add_view(cls, attr='product_autocomplete',
|
||||
route_name='{}.product_autocomplete'.format(route_prefix),
|
||||
renderer='json',
|
||||
permission='products.list')
|
||||
|
||||
|
||||
# TODO: deprecate / remove this
|
||||
CustomerOrdersView = CustomerOrderView
|
||||
|
||||
|
|
Loading…
Reference in a new issue