def setUp(self): self.case_ids = {'c1': 10, 'c2': 30, 'c3': 50} self.section_ids = {'s1': 2, 's2': 9} self.product_ids = {'p1': 1, 'p2': 3, 'p3': 5} self.domain = self._get_name_for_domain() create_domain(self.domain) SQLProduct.objects.bulk_create( [SQLProduct(product_id=id) for id in self.product_ids]) transactions_flat = [] self.transactions = {} for case, c_bal in self.case_ids.items(): for section, s_bal in self.section_ids.items(): for product, p_bal in self.product_ids.items(): bal = c_bal + s_bal + p_bal transactions_flat.append( STrans(case_id=case, section_id=section, product_id=product, action='soh', quantity=bal)) self.transactions.setdefault(case, {}).setdefault( section, {})[product] = bal self.new_stock_report, self.form = self.create_report( transactions_flat) create_models_for_stock_report(self.domain, self.new_stock_report)
def setUpClass(cls): super(StockReportDomainTest, cls).setUpClass() cls.case_ids = {'c1': 10, 'c2': 30, 'c3': 50} cls.section_ids = {'s1': 2, 's2': 9} cls.product_ids = {'p1': 1, 'p2': 3, 'p3': 5} SQLProduct.objects.bulk_create( [SQLProduct(product_id=id) for id in cls.product_ids])
def setUpClass(cls): cls.case_ids = {'c1': 10, 'c2': 30, 'c3': 50} cls.section_ids = {'s1': 2, 's2': 9} cls.product_ids = {'p1': 1, 'p2': 3, 'p3': 5} SQLProduct.objects.bulk_create([ SQLProduct(product_id=id) for id in cls.product_ids ])
def forwards(self, orm): # sync products first properties_to_sync = [ ('product_id', '_id'), 'domain', 'name', 'is_archived', ('code', 'code_'), 'description', 'category', 'program_id', 'cost', ('units', 'unit'), 'product_data', ] product_ids = [ r['id'] for r in Product.get_db().view( 'commtrack/products', reduce=False, ).all() ] for product in iter_docs(Product.get_db(), product_ids): sql_product = SQLProduct() for prop in properties_to_sync: if isinstance(prop, tuple): sql_prop, couch_prop = prop else: sql_prop = couch_prop = prop if couch_prop in product: setattr(sql_product, sql_prop, product[couch_prop]) sql_product.save() # now update stock states for ss in StockState.include_archived.all(): ss.sql_product = SQLProduct.objects.get(product_id=ss.product_id) ss.save()
def forwards(self, orm): # sync products first properties_to_sync = [ ('product_id', '_id'), 'domain', 'name', 'is_archived', ('code', 'code_'), 'description', 'category', 'program_id', 'cost', ('units', 'unit'), 'product_data', ] product_ids = [r['id'] for r in Product.get_db().view( 'commtrack/products', reduce=False, ).all()] for product in iter_docs(Product.get_db(), product_ids): sql_product = SQLProduct() for prop in properties_to_sync: if isinstance(prop, tuple): sql_prop, couch_prop = prop else: sql_prop = couch_prop = prop if couch_prop in product: setattr(sql_product, sql_prop, product[couch_prop]) sql_product.save() # now update stock states for ss in StockState.include_archived.all(): ss.sql_product = SQLProduct.objects.get(product_id=ss.product_id) ss.save()
def setUp(self): # create case self.case_id = uuid.uuid4().hex CommCareCase( _id=self.case_id, domain='fakedomain', ).save() self.product_id = uuid.uuid4().hex SQLProduct(product_id=self.product_id).save() self._stock_report = functools.partial(_stock_report, self.case_id, self.product_id) self._receipt_report = functools.partial(_receipt_report, self.case_id, self.product_id) self._test_config = ConsumptionConfiguration.test_config() self._compute_consumption = functools.partial( compute_consumption, self.case_id, self.product_id, now, configuration=self._test_config)