Refactor ordering worksheet to use shared logic
This commit is contained in:
parent
b529a005d8
commit
1b059c5293
4 changed files with 12 additions and 28 deletions
|
@ -245,7 +245,7 @@ class PurchaseView(MasterView):
|
|||
url = self.request.route_url(routes[batch.mode], uuid=batch.uuid)
|
||||
return tags.link_to(text, url)
|
||||
|
||||
items = [HTML.tag('li', c=render(batch)) for batch in batches]
|
||||
items = [HTML.tag('li', c=[render(batch)]) for batch in batches]
|
||||
return HTML.tag('ul', c=items)
|
||||
|
||||
def delete_instance(self, purchase):
|
||||
|
|
|
@ -53,6 +53,7 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
mobile_creatable = True
|
||||
rows_editable = True
|
||||
mobile_rows_editable = True
|
||||
has_worksheet = True
|
||||
|
||||
mobile_form_fields = [
|
||||
'vendor',
|
||||
|
@ -106,9 +107,9 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
# purchase
|
||||
f.remove_field('purchase')
|
||||
|
||||
def order_form(self):
|
||||
def worksheet(self):
|
||||
"""
|
||||
View for editing batch row data as an order form.
|
||||
View for editing batch row data as an order form worksheet.
|
||||
"""
|
||||
batch = self.get_instance()
|
||||
if batch.executed:
|
||||
|
@ -116,9 +117,8 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
|
||||
# organize existing batch rows by product
|
||||
order_items = {}
|
||||
for row in batch.data_rows:
|
||||
if not row.removed:
|
||||
order_items[row.product_uuid] = row
|
||||
for row in batch.active_rows():
|
||||
order_items[row.product_uuid] = row
|
||||
|
||||
# organize vendor catalog costs by dept / subdept
|
||||
departments = {}
|
||||
|
@ -164,7 +164,7 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
history = list(reversed(history))
|
||||
|
||||
title = self.get_instance_title(batch)
|
||||
return self.render_to_response('order_form', {
|
||||
return self.render_to_response('worksheet', {
|
||||
'batch': batch,
|
||||
'instance': batch,
|
||||
'instance_title': title,
|
||||
|
@ -212,7 +212,7 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
def decorate_order_form_cost(self, cost):
|
||||
pass
|
||||
|
||||
def order_form_update(self):
|
||||
def worksheet_update(self):
|
||||
"""
|
||||
Handles AJAX requests to update current batch, from Order Form view.
|
||||
"""
|
||||
|
@ -354,16 +354,6 @@ class OrderingBatchView(PurchasingBatchView):
|
|||
cls._batch_defaults(config)
|
||||
cls._defaults(config)
|
||||
|
||||
# ordering form
|
||||
config.add_tailbone_permission(permission_prefix, '{}.order_form'.format(permission_prefix),
|
||||
"Edit {} data as worksheet".format(model_title))
|
||||
config.add_route('{}.order_form'.format(route_prefix), '{}/{{{}}}/order-form'.format(url_prefix, model_key))
|
||||
config.add_view(cls, attr='order_form', route_name='{}.order_form'.format(route_prefix),
|
||||
permission='{}.order_form'.format(permission_prefix))
|
||||
config.add_route('{}.order_form_update'.format(route_prefix), '{}/{{{}}}/order-form/update'.format(url_prefix, model_key))
|
||||
config.add_view(cls, attr='order_form_update', route_name='{}.order_form_update'.format(route_prefix),
|
||||
renderer='json', permission='{}.order_form'.format(permission_prefix))
|
||||
|
||||
# download as Excel
|
||||
config.add_route('{}.download_excel'.format(route_prefix), '{}/{{uuid}}/excel'.format(url_prefix))
|
||||
config.add_view(cls, attr='download_excel', route_name='{}.download_excel'.format(route_prefix),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue