示例#1
0
    def test_ota_consumption(self):
        self.ct_settings.consumption_config = ConsumptionConfig(
            min_transactions=0,
            min_window=0,
            optimal_window=60,
        )
        self.ct_settings.ota_restore_config = StockRestoreConfig(
            section_to_consumption_types={'stock': 'consumption'})
        set_default_consumption_for_domain(self.domain.name, 5)

        amounts = [(p._id, i * 10) for i, p in enumerate(self.products)]
        report = _report_soh(amounts, self.sp._id, 'stock')
        balance_blocks = _get_ota_balance_blocks(self.ct_settings, 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=json_format_datetime(report.date),
            ),
            stock_block,
        )
        check_xml_line_by_line(
            self,
            balance_ota_block(
                self.sp,
                'consumption',
                [(p._id, 5) for p in self.products],
                datestring=json_format_datetime(report.date),
            ),
            consumption_block,
        )
示例#2
0
    def test_ota_consumption(self):
        self.ct_settings.consumption_config = ConsumptionConfig(min_transactions=0, min_window=0, optimal_window=60)
        self.ct_settings.ota_restore_config = 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 = [(p._id, i * 10) for i, p in enumerate(self.products)]
        report = _report_soh(amounts, self.sp.case_id, "stock")
        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=json_format_datetime(report.date)),
            stock_block,
        )
        check_xml_line_by_line(
            self,
            balance_ota_block(
                self.sp,
                "consumption",
                [(p._id, 150) for p in self.products],
                datestring=json_format_datetime(report.date),
            ),
            consumption_block,
        )
示例#3
0
 def test_ota_multiple_stocks(self):
     user = self.user
     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)
     ]
     report_date = _report_soh(amounts, self.sp.case_id, self.domain.name)
     balance_blocks = get_ota_balance_xml(self.domain, 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],
         )
示例#4
0
 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],
         )
示例#5
0
    def test_ota_multiple_stocks(self):
        user = self.user
        date = datetime.utcnow()
        report = StockReport.objects.create(
            form_id=uuid.uuid4().hex,
            date=date,
            type=stockconst.REPORT_TYPE_BALANCE)
        amounts = [(p._id, i * 10) for i, p in enumerate(self.products)]

        section_ids = sorted(('stock', 'losses', 'consumption'))
        for section_id in section_ids:
            _report_soh(amounts, self.sp._id, section_id, report=report)

        balance_blocks = get_ota_balance_xml(user)
        self.assertEqual(3, len(balance_blocks))
        for i, section_id in enumerate(section_ids):
            check_xml_line_by_line(
                self,
                balance_ota_block(
                    self.sp,
                    section_id,
                    amounts,
                    datestring=json_format_datetime(date),
                ),
                balance_blocks[i],
            )
示例#6
0
    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,
        )
示例#7
0
 def test_ota_basic(self):
     user = self.user
     amounts = [(p._id, i * 10) for i, p in enumerate(self.products)]
     report = _report_soh(amounts, self.sp.case_id, "stock")
     check_xml_line_by_line(
         self,
         balance_ota_block(self.sp, "stock", amounts, datestring=json_format_datetime(report.date)),
         get_ota_balance_xml(self.domain, user)[0],
     )
示例#8
0
    def test_ota_consumption(self):
        self.ct_settings.sync_consumption_fixtures = True
        self.ct_settings.consumption_config = ConsumptionConfig(
            min_transactions=0,
            min_window=0,
            optimal_window=60,
        )
        self.ct_settings.ota_restore_config = 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)
        ]
        report_date = _report_soh(amounts, self.sp.case_id, self.domain.name)
        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,
        )
示例#9
0
 def test_ota_basic(self):
     user = self.user
     amounts = [(p._id, i * 10) for i, p in enumerate(self.products)]
     report = _report_soh(amounts, self.sp._id, 'stock')
     check_xml_line_by_line(
         self,
         balance_ota_block(
             self.sp,
             'stock',
             amounts,
             datestring=json_format_datetime(report.date),
         ),
         get_ota_balance_xml(user)[0],
     )
示例#10
0
    def test_ota_consumption(self):
        self.ct_settings.consumption_config = ConsumptionConfig(
            min_transactions=0,
            min_window=0,
            optimal_window=60,
        )
        self.ct_settings.ota_restore_config = StockRestoreConfig(
            section_to_consumption_types={'stock': 'consumption'}
        )
        set_default_consumption_for_domain(self.domain.name, 5)

        amounts = [(p._id, i*10) for i, p in enumerate(self.products)]
        report = _report_soh(amounts, self.sp._id, 'stock')
        balance_blocks = _get_ota_balance_blocks(self.ct_settings, 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=json_format_datetime(report.date),
            ),
            stock_block,
        )
        check_xml_line_by_line(
            self,
            balance_ota_block(
                self.sp,
                'consumption',
                [(p._id, 5) for p in self.products],
                datestring=json_format_datetime(report.date),
            ),
             consumption_block,
        )
示例#11
0
 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],
     )
示例#12
0
 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],
     )
示例#13
0
    def test_ota_multiple_stocks(self):
        user = self.user
        date = datetime.utcnow()
        report = StockReport.objects.create(form_id=uuid.uuid4().hex, date=date, type=stockconst.REPORT_TYPE_BALANCE)
        amounts = [(p._id, i * 10) for i, p in enumerate(self.products)]

        section_ids = sorted(("stock", "losses", "consumption"))
        for section_id in section_ids:
            _report_soh(amounts, self.sp.case_id, section_id, report=report)

        balance_blocks = get_ota_balance_xml(self.domain, user)
        self.assertEqual(3, len(balance_blocks))
        for i, section_id in enumerate(section_ids):
            check_xml_line_by_line(
                self,
                balance_ota_block(self.sp, section_id, amounts, datestring=json_format_datetime(date)),
                balance_blocks[i],
            )