Beispiel #1
0
    def set_up(self):
        self.FILE_NAME = "20141020_2IAEW4.xlsx"
        test_date = datetime.datetime.strptime("Fri, 19 Dec 2014 20:20:57", '%a, %d %b %Y %H:%M:%S')
        self.provider_suite = ProviderTestSuite(self.client, self.application)

        self.mailinvoice_provider = MailInvoiceTestSuite(self.client, self.application)
        self.mail_stub = self.mailinvoice_provider.get_stub(test_date, self.FILE_NAME)

        self.test_provider = self.provider_suite.create_test_provider()
        self.test_date = test_date.date()
Beispiel #2
0
    def set_up(self):
        self.FILE_NAME = "20141020_2IAEW4.xlsx"

        self.acceptance_suite = AcceptanceSuite(self.client, self.application)

        self.pointsale_suite = PointSaleSuite(self.client, self.application)

        self.application_suite = ApplicationSuite(
            self.client, self.application)

        self.provider_suite = ProviderTestSuite(self.client, self.application)
        self.test_provider_id, _, _, _ = (
            self.provider_suite.create_test_provider())

        self.invoice_suite = MailInvoiceTestSuite(
            self.client, self.application)
        with self.application.app_context():
            pointsale = self.pointsale_suite.create_test_pointsale(
                name=u"ШШК", address=u"Наб. Челны")
            self.pointsale_id = pointsale.id
Beispiel #3
0
class InvoiceTestCase(BaseTestCase):
    def set_up(self):
        self.FILE_NAME = "20141020_2IAEW4.xlsx"
        test_date = datetime.datetime.strptime("Fri, 19 Dec 2014 20:20:57", '%a, %d %b %Y %H:%M:%S')
        self.provider_suite = ProviderTestSuite(self.client, self.application)

        self.mailinvoice_provider = MailInvoiceTestSuite(self.client, self.application)
        self.mail_stub = self.mailinvoice_provider.get_stub(test_date, self.FILE_NAME)

        self.test_provider = self.provider_suite.create_test_provider()
        self.test_date = test_date.date()

    def testIncomingInvoiceWithSavePrice(self):
        with self.application.app_context():
            self.incoming_invoice()
            self.price_invoice()

    def price_invoice(self):
        ITEMS = (
            (u"Men's Health №11(196)", 106.0, 125.0),
            (u"Men's Health/мини формата/№11(117)", 85.0, 105.0),
            (u"Святые №29(12)Лука Войно-Ясенецкий", 15.0, 18.0),
            (u"Ума палата.Спецвыпуск.Календарь Озорные котята б/н 2015", 34.0, 42.0),
            (u"Советский спорт-понедельник №20.10(20141020)", 46.0, 50.0),
        )

        self.assertEqual(Price.query.count(), 0)
        self.assertEqual(PriceParish.query.count(), 0)

        # сохраняем цены
        resp = self.mailinvoice_provider.price_invoice(self.invoice.id, datas=ITEMS)

        self.assertEqual(resp.status_code, 200)

        self.assertEqual(Price.query.count(), len(ITEMS))
        self.assertEqual(PriceParish.query.count(), len(ITEMS))

        for item in ITEMS:
            name, gross, retail = item
            attrs = self.mailinvoice_provider._get_item(self.invoice.id, name, gross, retail)
            good = self.mailinvoice_provider._get_good(self.invoice.id, name)
            commodity = good.commodity
            price = good.price
            if commodity.numeric:
                price_parish = PriceParish.query.filter(
                    PriceParish.commodity_id == good.commodity_id,
                    PriceParish.number_local_from == attrs['number_local'],
                    PriceParish.number_global_from == attrs['number_global']
                ).one()
            else:
                price_parish = PriceParish.query.filter(
                    PriceParish.commodity_id == good.commodity_id,
                    PriceParish.date_from == self.invoice.date
                ).one()

            self.assertEqual(float(price.price_gross), gross)
            self.assertEqual(float(price.price_retail), retail)
            self.assertEqual(price_parish.number_local_from, attrs['number_local'])
            self.assertEqual(price_parish.number_global_from, attrs['number_global'])
            self.assertEqual(price_parish.date_from, self.invoice.date)
            self.assertEqual(float(price_parish.NDS), attrs['NDS'])
            self.assertEqual(float(price_parish.price_prev), attrs['price_prev'])
            self.assertEqual(float(price_parish.price_post), attrs['price_post'])
            self.assertEqual(price_parish.price_id, price.id)

    def incoming_invoice(self):
        ITEMS = (
            (u"Men's Health №11(196)", 3, 0, 3, 58.00, 63.8000, 174.00, 10, 17.40, 191.40, u"1МЖ", 0, 3),
            (u"Men's Health/мини формата/№11(117)",	2,	0,	2,	48.72,	53.5900,	97.44,	10,	9.74,	107.18,	u"1МЖ", 0, 2),
            (u"Грамотейка №11(61)",	4,	0,	4,	11.48,	12.6300,	45.92,	10,	4.59,	50.51,	u"2ДЛ", 0, 4),
            (u"Губка Боб и его друзья №21(108)",	2,	0,	2,	75.29,	82.8200,	150.58,	10,	15.06,	165.64,	u"2ДЛ", 0, 2),
            (u"Советский спорт-понедельник №20.10(20141020)", 11, 0,	11,	14.74, 16.2100, 162.14,	10, 16.21,	178.35, u"1СП", 11, 0),
            (u"Ума палата.Спецвыпуск.Календарь Озорные котята б/н 2015",	5, 0, 5, 29.00, 31.9000, 145.00, 10, 14.50, 159.50, u"1ОБ", 0, 5)
        )
        self.assertEqual(InvoiceItem.query.count(), 0)
        self.assertEqual(Good.query.count(), 0)
        self.assertEqual(Mail.query.count(), 0)
        self.assertEqual(Invoice.query.count(), 0)
        self.mailinvoice_provider.handle_invoice(self.mail_stub.date_, self.FILE_NAME, 1)
        self.assertEqual(Mail.query.count(), 1)
        self.assertEqual(Invoice.query.count(), 1)
        invoice = Invoice.query.first()
        self.invoice = invoice

        resp = self.mailinvoice_provider._mails()
        self.assertEqual(resp.status_code, 200)
        data = self._deserialize(resp.data)
        self.assertEqual(data['count'], 1)

        resp = self.mailinvoice_provider._invoice_items(self.invoice.id)
        self.assertEqual(resp.status_code, 200)
        data = self._deserialize(resp.data)
        self.assertEqual(len(data['items']), 41)

        self.assertEqual(invoice.number, u'О-00064184')
        self.assertEqual(invoice.date, self.test_date)
        self.assertEqual(invoice.provider_id, self.test_provider[0])
        self.assertEqual(float(invoice.sum_without_NDS), float(9153.12))
        self.assertEqual(float(invoice.sum_with_NDS), float(10076.83))
        self.assertEqual(float(invoice.sum_NDS), float(923.71))
        self.assertEqual(float(invoice.weight), float(71.408))
        self.assertEqual(invoice.responsible, u"Зарипов Б. Р.")

        mail = Mail.query.first()
        self.assertEqual(mail.title, self.mail_stub.title)
        self.assertEqual(mail.date.ctime(), self.mail_stub.date_.ctime())
        self.assertEqual(mail.from_, self.mail_stub.from_)
        self.assertEqual(mail.to, self.mail_stub.to_)
        self.assertEqual(json.loads(mail.files), self.mail_stub.files)
        self.assertEqual(mail.is_handling, True)
        self.assertEqual(mail.invoice_id, invoice.id)

        self.assertEqual(InvoiceItem.query.count(), 41)
        self.assertEqual(Good.query.count(), 41)

        for it in ITEMS:
            name, ord_cnt, reord_cnt, cnt, pr_wo_N, pr_w_N, s_wo_N, r_N, s_N, s_w_N, th, cnt_pk, plc = it
            n, l, g = get_name_number(name)
            item = InvoiceItem.query.filter(
                InvoiceItem.name == n,
                InvoiceItem.invoice_id == self.invoice.id
            ).one()

            self.assertEqual(item.full_name, name)
            self.assertEqual(item.number_local, l)
            self.assertEqual(item.number_global, g)
            self.assertEqual(item.count_order, ord_cnt)
            self.assertEqual(item.count_postorder, reord_cnt)
            self.assertEqual(item.count, cnt)
            self.assertEqual(float(item.price_without_NDS), pr_wo_N)
            self.assertEqual(float(item.price_with_NDS), pr_w_N)
            self.assertEqual(float(item.sum_without_NDS), s_wo_N)
            self.assertEqual(float(item.sum_NDS), s_N)
            self.assertEqual(float(item.rate_NDS), r_N)
            self.assertEqual(float(item.sum_with_NDS), s_w_N)
            self.assertEqual(item.thematic, th)
            self.assertEqual(item.count_whole_pack, cnt_pk)
            self.assertEqual(item.placer, plc)
            self.assertIsNotNone(item.good_id)

            comm = Commodity.query.filter(Commodity.name == n).one()
            self.assertEqual(comm.thematic, th)
            self.assertEqual(comm.numeric, bool(l) and bool(g))

            good = Good.query.get(item.good_id)
            self.assertEqual(good.commodity_id, comm.id)
            self.assertEqual(good.full_name, name)
            self.assertEqual(good.number_local, l)
            self.assertEqual(good.number_global, g)
            self.assertIsNone(good.price)
class ChangePriceTestCase(BaseTestCase):

    def set_up(self):
        self.FILE_NAME = "20141020_2IAEW4.xlsx"
        test_date = datetime.datetime.strptime("Fri, 19 Dec 2014 20:20:57", '%a, %d %b %Y %H:%M:%S')

        self.FILE_NAME2 = "20141021_2IAEW4.xlsx"
        test_date2 = datetime.datetime.strptime("Fri, 25 Dec 2014 19:15:13", '%a, %d %b %Y %H:%M:%S')

        self.mailinvoice_provider = MailInvoiceTestSuite(self.client, self.application)
        self.provider_suite = ProviderTestSuite(self.client, self.application)
        self.provider_suite.create_test_provider()

        self.mail_stub = self.mailinvoice_provider.get_stub(test_date, self.FILE_NAME)
        self.mail_stub2 = self.mailinvoice_provider.get_stub(test_date2, self.FILE_NAME2)

    def testChangePriceRest(self):
        with self.application.app_context():
            self.invoice_change_price()

    def invoice_change_price(self):
        """
        Меняется ли цена у товара при приходе накладной с измененными ценами.
        """
        ITEMS = (
            (u"Men's Health №11(196)", 95.0, 120.0),
            (u"Men's Health/мини формата/№11(117)", 86.0, 105.0),
            (u"Ума палата.Спецвыпуск.Календарь Год козы б/н 2015", 24.0, 30.0),
            (u"Ума палата.Спецвыпуск.Календарь Гороскоп б/н 2015", 23.0, 29.0),
            (u'Цифровые сканворды №42(680)', 14.0, 17.0),
            (u'Числовые сканворды №42(466)', 11.0, 14.0),
            (u"Моя семья №41(735)", 22.0, 26.0)
        )

        CIP_SCAN = u'Цифровые сканворды №42(680)'
        CH_SCAN = u'Числовые сканворды №42(466)'
        MN = u"Men's Health №12(197)"
        MN_MINI = u"Men's Health/мини формата/№12(118)"
        MIND_PAL = u"Ума палата.Спецвыпуск.Календарь Год козы б/н 2015"
        MIND_GOR = u"Ума палата.Спецвыпуск.Календарь Гороскоп б/н 2015"

        PRICE_CH = {
            MN_MINI: (90.0, 110.0),
            MIND_PAL: (25.0, 32.0)
        }

        #проверка вычисления изменения цены товара
        ITEM_CHANGE_PRICE = (
            (CIP_SCAN, False),
            (CH_SCAN, True),
            (MN, True),
            (MN_MINI, True),
            (MIND_PAL, True),
            (MIND_GOR, True)
        )

        #проверка создания новой цены
        ITEM_NEW_PRICE = (
            (CIP_SCAN, False),
            (CH_SCAN, False),
            (MN, False),
            (MN_MINI, True),
            (MIND_PAL, True),
            (MIND_GOR, False)
        )

        #принимаем накладную исходную
        self.mailinvoice_provider.handle_invoice(self.mail_stub.date_, self.FILE_NAME, 1)
        invoice = Invoice.query.first()

        for item in ITEMS:
            name, _, _ = item
            inv_item = self.mailinvoice_provider._get_invoiceitem(invoice.id, name)
            price = PriceService.generate_price_stub_item(inv_item)
            self.assertEqual(price.is_change, False)
        #раставляем цены на некоторые товары
        self.mailinvoice_provider.price_invoice(invoice.id, datas=ITEMS)

        #принимает накладную с измененными ценами
        self.mailinvoice_provider.handle_invoice(self.mail_stub2.date_, self.FILE_NAME2, 2)
        invoice2 = Invoice.query.filter(
            Invoice.id!=invoice.id
        ).one()
        #проверяем, оповещает ли система об измененных ценах
        for item in ITEM_CHANGE_PRICE:
            name, is_ch = item
            inv_item = self.mailinvoice_provider._get_invoiceitem(invoice2.id, name)
            price = PriceService.generate_price_stub_item(inv_item)
            self.assertEqual(price.is_change, is_ch)
        #сохраняем новые цены

        self.mailinvoice_provider.price_invoice(invoice2.id, datas=[(x, PRICE_CH[x][0], PRICE_CH[x][1]) for x in PRICE_CH])

        for item in ITEM_NEW_PRICE:
            name, new_pr = item
            inv_item = self.mailinvoice_provider._get_invoiceitem(invoice2.id, name)
            good = self.mailinvoice_provider._get_good(invoice2.id, name)
            prices_parish = PriceParish.query.filter(
                PriceParish.commodity_id == good.commodity.id,
            )
            self.assertEqual(prices_parish.count(), 2 if new_pr else 1)
            if new_pr and name in PRICE_CH:
                prices_gross, price_retail = PRICE_CH[name]
                self.assertEqual(float(good.price.price_retail), price_retail)
                self.assertEqual(float(good.price.price_gross), prices_gross)
Beispiel #5
0
class AcceptanceTest(BaseTestCase):
    def set_up(self):
        self.FILE_NAME = "20141020_2IAEW4.xlsx"

        self.acceptance_suite = AcceptanceSuite(self.client, self.application)

        self.pointsale_suite = PointSaleSuite(self.client, self.application)

        self.application_suite = ApplicationSuite(
            self.client, self.application)

        self.provider_suite = ProviderTestSuite(self.client, self.application)
        self.test_provider_id, _, _, _ = (
            self.provider_suite.create_test_provider())

        self.invoice_suite = MailInvoiceTestSuite(
            self.client, self.application)
        with self.application.app_context():
            pointsale = self.pointsale_suite.create_test_pointsale(
                name=u"ШШК", address=u"Наб. Челны")
            self.pointsale_id = pointsale.id

    def invoice_(self):
        """
        Принимаем накладную из файла FILE_NAME
        """
        self.invoice_suite.handle_invoice(
            datetime=datetime.now(), file_name=self.FILE_NAME, mail_id=1)
        return Invoice.query.first().id

    def price_to_good(self, good_id):
        return Good.query.filter(
            Good.id == good_id
        ).one().price

    def priceparish_to_good(self, good_id):
        good = Good.query.get(good_id)
        return PriceParish.query.filter(
            PriceParish.commodity_id == good.commodity_id,
            PriceParish.number_local_from == good.number_local,
            PriceParish.number_global_from == good.number_global
        )

    def invoice_count(self):
        return Invoice.query.count()

    def acceptance_count(self):
        return Acceptance.query.count()

    def acceptance_items(self, id):
        return AcceptanceItems.query.filter(
            AcceptanceItems.acceptance_id == id
        )

    def acceptance_item(self, id):
        return AcceptanceItems.query.filter(
            AcceptanceItems.id == id
        ).one()

    def pointsale_items(self, id):
        return PointSaleItem.query.filter(
            PointSaleItem.pointsale_id == id
        )

    def invoice_items(self, id):
        return InvoiceItem.query.filter(
            InvoiceItem.invoice_id == id
        )

    def success_stories_mail(self, date):
        invoice_id = self.invoice_()
        return invoice_id, self.acceptance_suite.create(
            date=date, type=MAIL, invoice_id=invoice_id,
            pointsale_id=self.pointsale_id)