Move logic for Order Form worksheet into purchase batch handler
i.e. get it out of Tailbone!
This commit is contained in:
parent
1db6d642e7
commit
12b0ac1037
|
@ -201,8 +201,10 @@ class OrderingBatchView(PurchasingBatchView):
|
||||||
|
|
||||||
# organize vendor catalog costs by dept / subdept
|
# organize vendor catalog costs by dept / subdept
|
||||||
departments = {}
|
departments = {}
|
||||||
costs = self.get_order_form_costs(batch.vendor)
|
costs = self.handler.get_order_form_costs(self.Session(), batch.vendor)
|
||||||
costs = self.sort_order_form_costs(costs)
|
costs = self.handler.sort_order_form_costs(costs)
|
||||||
|
costs = list(costs) # we must have a stable list for the rest of this
|
||||||
|
self.handler.decorate_order_form_costs(batch, costs)
|
||||||
for cost in costs:
|
for cost in costs:
|
||||||
|
|
||||||
department = cost.product.department
|
department = cost.product.department
|
||||||
|
@ -233,11 +235,8 @@ class OrderingBatchView(PurchasingBatchView):
|
||||||
subdept_costs.append(cost)
|
subdept_costs.append(cost)
|
||||||
cost._batchrow = order_items.get(cost.product_uuid)
|
cost._batchrow = order_items.get(cost.product_uuid)
|
||||||
|
|
||||||
# do anything else needed to satisfy template display requirements etc.
|
|
||||||
self.decorate_order_form_cost(cost)
|
|
||||||
|
|
||||||
# fetch recent purchase history, sort/pad for template convenience
|
# fetch recent purchase history, sort/pad for template convenience
|
||||||
history = self.get_order_form_history(batch, costs, 6)
|
history = self.handler.get_order_form_history(batch, costs, 6)
|
||||||
for i in range(6 - len(history)):
|
for i in range(6 - len(history)):
|
||||||
history.append(None)
|
history.append(None)
|
||||||
history = list(reversed(history))
|
history = list(reversed(history))
|
||||||
|
@ -260,41 +259,6 @@ class OrderingBatchView(PurchasingBatchView):
|
||||||
'ignore_cases': not self.handler.allow_cases(),
|
'ignore_cases': not self.handler.allow_cases(),
|
||||||
})
|
})
|
||||||
|
|
||||||
def get_order_form_history(self, batch, costs, count):
|
|
||||||
|
|
||||||
# fetch last 6 purchases for this vendor, organize line items by product
|
|
||||||
history = []
|
|
||||||
purchases = self.Session.query(model.Purchase)\
|
|
||||||
.filter(model.Purchase.vendor == batch.vendor)\
|
|
||||||
.filter(model.Purchase.status >= self.enum.PURCHASE_STATUS_ORDERED)\
|
|
||||||
.order_by(model.Purchase.date_ordered.desc(), model.Purchase.created.desc())\
|
|
||||||
.options(orm.joinedload(model.Purchase.items))
|
|
||||||
for purchase in purchases[:count]:
|
|
||||||
items = {}
|
|
||||||
for item in purchase.items:
|
|
||||||
items[item.product_uuid] = item
|
|
||||||
history.append({'purchase': purchase, 'items': items})
|
|
||||||
|
|
||||||
return history
|
|
||||||
|
|
||||||
def get_order_form_costs(self, vendor):
|
|
||||||
return self.Session.query(model.ProductCost)\
|
|
||||||
.join(model.Product)\
|
|
||||||
.outerjoin(model.Brand)\
|
|
||||||
.filter(model.ProductCost.vendor == vendor)\
|
|
||||||
.options(orm.joinedload(model.ProductCost.product)\
|
|
||||||
.joinedload(model.Product.department))\
|
|
||||||
.options(orm.joinedload(model.ProductCost.product)\
|
|
||||||
.joinedload(model.Product.subdepartment))
|
|
||||||
|
|
||||||
def sort_order_form_costs(self, costs):
|
|
||||||
return costs.order_by(model.Brand.name,
|
|
||||||
model.Product.description,
|
|
||||||
model.Product.size)
|
|
||||||
|
|
||||||
def decorate_order_form_cost(self, cost):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def worksheet_update(self):
|
def worksheet_update(self):
|
||||||
"""
|
"""
|
||||||
Handles AJAX requests to update the order quantities for some row
|
Handles AJAX requests to update the order quantities for some row
|
||||||
|
|
Loading…
Reference in a new issue