def _create_stock_state(self, product, consumption): xform = XFormInstance.get('test-xform') loc = Location.by_site_code(TEST_DOMAIN, 'garms') now = datetime.datetime.utcnow() report = StockReport(form_id=xform._id, date=(now - datetime.timedelta(days=10)).replace( second=0, microsecond=0), type='balance', domain=TEST_DOMAIN) report.save() stock_transaction = StockTransaction( case_id=loc.linked_supply_point().get_id, product_id=product.get_id, sql_product=SQLProduct.objects.get(product_id=product.get_id), section_id='stock', type='stockonhand', stock_on_hand=2 * consumption, report=report) stock_transaction.save() report = StockReport(form_id=xform._id, date=now.replace(second=0, microsecond=0), type='balance', domain=TEST_DOMAIN) report.save() stock_transaction = StockTransaction( case_id=loc.linked_supply_point().get_id, product_id=product.get_id, sql_product=SQLProduct.objects.get(product_id=product.get_id), section_id='stock', type='stockonhand', stock_on_hand=consumption, report=report) stock_transaction.save()
def _get_model_for_stock_report(domain, stock_report_helper): return StockReport( form_id=stock_report_helper.form_id, date=stock_report_helper.timestamp, type=stock_report_helper.report_type, domain=domain, server_date=stock_report_helper.server_date, )