def test_ota_multiple_stocks(self): section_ids = sorted(('stock', 'losses', 'consumption')) amounts = [ SohReport(section_id=section_id, product_id=p._id, amount=i * 10) for section_id in section_ids for i, p in enumerate(self.products) ] form_id, report_date = _report_soh(amounts, self.sp.case_id, self.domain.name) self.addCleanup(self.delete_ledger_transactions, form_id) balance_blocks = util.get_ota_balance_xml(self.domain, self.user) self.assertEqual(3, len(balance_blocks)) for i, section_id in enumerate(section_ids): reports = [ report for report in amounts if report.section_id == section_id ] check_xml_line_by_line( self, balance_ota_block( self.sp, section_id, reports, datestring=report_date, ), balance_blocks[i], )
def test_ota_consumption(self): self.ct_settings.sync_consumption_fixtures = True self.ct_settings.consumptionconfig = ConsumptionConfig( min_transactions=0, min_window=0, optimal_window=60, ) self.ct_settings.stockrestoreconfig = StockRestoreConfig( section_to_consumption_types={'stock': 'consumption'}) set_default_monthly_consumption_for_domain(self.domain.name, 5 * DAYS_IN_MONTH) self._save_settings_and_clear_cache() amounts = [ SohReport(section_id='stock', product_id=p._id, amount=i * 10) for i, p in enumerate(self.products) ] form_id, report_date = _report_soh(amounts, self.sp.case_id, self.domain.name) self.addCleanup(self.delete_ledger_transactions, form_id) balance_blocks = _get_ota_balance_blocks(self.domain, self.user) self.assertEqual(2, len(balance_blocks)) stock_block, consumption_block = balance_blocks check_xml_line_by_line( self, balance_ota_block( self.sp, 'stock', amounts, datestring=report_date, ), stock_block, ) check_xml_line_by_line( self, balance_ota_block( self.sp, 'consumption', [ SohReport(section_id='', product_id=p._id, amount=150) for p in self.products ], datestring=report_date, ), consumption_block, )
def test_ota_basic(self): amounts = [ SohReport(section_id='stock', product_id=p._id, amount=i * 10) for i, p in enumerate(self.products) ] report_date = _report_soh(amounts, self.sp.case_id, self.domain.name) check_xml_line_by_line( self, balance_ota_block( self.sp, 'stock', amounts, datestring=report_date, ), util.get_ota_balance_xml(self.domain, self.user)[0], )