예제 #1
0
파일: pillows.py 프로젝트: tsinkala/core-hq
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})
예제 #2
0
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
    })
예제 #3
0
    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)
예제 #4
0
파일: v0_1.py 프로젝트: birdsarah/core-hq
 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'])
예제 #5
0
 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'])