diff --git a/tailbone/views/purchasing/ordering.py b/tailbone/views/purchasing/ordering.py index 15ce6f5b..77e631f5 100644 --- a/tailbone/views/purchasing/ordering.py +++ b/tailbone/views/purchasing/ordering.py @@ -201,8 +201,10 @@ class OrderingBatchView(PurchasingBatchView): # organize vendor catalog costs by dept / subdept departments = {} - costs = self.get_order_form_costs(batch.vendor) - costs = self.sort_order_form_costs(costs) + costs = self.handler.get_order_form_costs(self.Session(), batch.vendor) + 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: department = cost.product.department @@ -233,11 +235,8 @@ class OrderingBatchView(PurchasingBatchView): subdept_costs.append(cost) 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 - 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)): history.append(None) history = list(reversed(history)) @@ -260,41 +259,6 @@ class OrderingBatchView(PurchasingBatchView): '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): """ Handles AJAX requests to update the order quantities for some row