def compute_consumption(product_case, window_end, get_base_action): window_start = window_end - timedelta(days=CONSUMPTION_WINDOW) overshoot_start = window_start - timedelta(days=WINDOW_OVERSHOOT) transactions = list(StockTransaction.by_product(product_case, to_ts(overshoot_start), to_ts(window_end))) transactions.sort(key=lambda tx: (tx.received_on, tx.processing_order)) return _compute_consumption(transactions, window_start, get_base_action, {'min_periods': MIN_PERIODS, 'min_window': MIN_WINDOW})
def compute_consumption(product_case, window_end, get_base_action): window_start = window_end - timedelta(days=CONSUMPTION_WINDOW) overshoot_start = window_start - timedelta(days=WINDOW_OVERSHOOT) transactions = list( StockTransaction.by_product(product_case, to_ts(overshoot_start), to_ts(window_end))) transactions.sort(key=lambda tx: (tx.received_on, tx.processing_order)) return _compute_consumption(transactions, window_start, get_base_action, { 'min_periods': MIN_PERIODS, 'min_window': MIN_WINDOW })
def test_stock_transaction(self): stock_transaction = StockTransaction.force_wrap({ "action": "consumption", "product_entry": "9d14b21ab5ae6fb39d00d575c54d406b", "product": "a660733caacc170577445d13755b3be0", "@inferred": "true", "value": "5", "location_id": "6da439e2eb717e6b80a2d871956273f9", "received_on": "2013-01-11T00:00:00Z" }) result = { "action": "consumption", "product_entry": "9d14b21ab5ae6fb39d00d575c54d406b", "product": "a660733caacc170577445d13755b3be0", "inferred": True, "value": 5, "location_id": "6da439e2eb717e6b80a2d871956273f9", "received_on": datetime.datetime(2013, 01, 11, 00, 00, 00), } for key, value in result.items(): self.assertEqual(getattr(stock_transaction, key), value)
def obj_get_list(self, request, **kwargs): location_id = request.GET.get("location_id", None) if location_id: return StockTransaction.by_location(kwargs['domain'], location_id) else: return StockTransaction.by_domain(kwargs['domain'])