예제 #1
0
class YarusTest(unittest.TestCase):
    valid_receipt_items = [
        pyofd.ReceiptEntry(title='GR   10 г №0047 зеленый Артиkул 372426421'    , qty=2, price='16.00' , subtotal='32.00' ),
        pyofd.ReceiptEntry(title='мm  50 m №03 пoд св.mе дь Apтикул 4319338852' , qty=2, price='160.10', subtotal='320.20'),
        pyofd.ReceiptEntry(title='GR   10 г №0142 kрemoвый Аpт икул 972482351'  , qty=1, price='16.38' , subtotal='16.38' ),
        pyofd.ReceiptEntry(title='0 г №0109А св.пeрсиkовый Аpти кул 10360008322', qty=1, price='16.38' , subtotal='16.38' ),
        pyofd.ReceiptEntry(title='GR   10 г №0053 koринчeвый Apтиkул 972344641' , qty=1, price='16.38' , subtotal='16.38' ),
        pyofd.ReceiptEntry(title='33 мm бoльшиe/в блист eрe Aртиkул 1754871892'  , qty=1, price='108.29', subtotal='108.29'),
        pyofd.ReceiptEntry(title='GR   10 г №0012М сеpый Aртиkул 10359922602'   , qty=1, price='16.37' , subtotal='16.37' ),
    ]

    def setUp(self):
        self.provider = pyofd.providers.yarus.ofdYarus()

    def test_provider_invalid(self):
        self.assertIsNone(self.provider.validate(fpd='0'*10, rn_kkt='0'*16))

    def test_provider_minimal(self):
        self.assertIsNotNone(self.provider.validate(fpd='4023651155', rn_kkt='0000691164058512'))

    def test_valid_parse(self):
        result = self.provider.validate(fpd='4023651155', rn_kkt='0000691164058512')
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_provider(self):
        receipt = pyofd.OFDReceipt(fpd='4023651155', rn_kkt='0000691164058512')

        result = receipt.load_receipt()

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)
예제 #2
0
class YandexTest(unittest.TestCase):
    valid_receipt_items = [
        pyofd.ReceiptEntry(title='Перевозка пассажиров и багажа',
                           qty=1,
                           price='390.00',
                           subtotal='390.00'),
    ]

    def setUp(self):
        self.provider = pyofd.providers.yandex.ofdYandex()

    def test_provider_invalid(self):
        self.assertIsNone(self.provider.validate(rn_kkt=0, fd=0, fpd=0))

    def test_provider_minimal(self):
        self.assertIsNotNone(
            self.provider.validate(rn_kkt=840594031594,
                                   fd=238872,
                                   fpd=3826178549))

    def test_valid_parse(self):
        result = self.provider.validate(rn_kkt=840594031594,
                                        fd=238872,
                                        fpd=3826178549)
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_full_parse(self):
        result = self.provider.validate(rn_kkt=840594031594,
                                        fd=238872,
                                        fpd=3826178549)
        self.assertIsNotNone(result)
        self.assertEqual(
            'ОБЩЕСТВО С ОГРАНИЧЕННОЙ ОТВЕТСТВЕННОСТЬЮ "ЯНДЕКС.ТАКСИ"',
            result.seller_name)
        self.assertEqual('Московская обл., Мытищи, ул Силикатная, 19',
                         result.seller_address)
        self.assertEqual('7704340310', result.inn)
        self.assertEqual(Decimal('390'), result.total)
        self.assertEqual('8710000101113214', result.fn)
        self.assertEqual('3826178549', result.fpd)
        self.assertEqual('undefined', result.cashier)
        self.assertEqual('0000840594031594', result.rn_kkt)
        self.assertEqual(
            datetime(year=2018, month=3, day=7, hour=10, minute=57),
            result.purchase_date)

    def test_provider(self):
        receipt = pyofd.OFDReceipt(rn_kkt=840594031594,
                                   fd=238872,
                                   fpd=3826178549)

        result = receipt.load_receipt()

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)
예제 #3
0
파일: ofd.py 프로젝트: taowang7/pyofd
    def _parse_entry(entry):
        try:
            subtotal = _to_decimal(entry['Total']) / 100
            quantity = _to_decimal(entry['Quantity'])
            price = _to_decimal(entry['Price']) / 100
            name = _strip(entry['Name'])

            return pyofd.ReceiptEntry(name, price, quantity, subtotal)
        except KeyError:
            return None
예제 #4
0
파일: kontur.py 프로젝트: taowang7/pyofd
    def _parse_entry(entry):
        try:
            subtotal = _to_decimal(entry['total'])
            quantity = _to_decimal(entry['count'])
            price = _to_decimal(entry['price'])
            name = _strip(entry['name'])

            return pyofd.ReceiptEntry(name, price, quantity, subtotal)
        except KeyError:
            return None
예제 #5
0
class KonturTest(unittest.TestCase):
    valid_receipt_items = [
        pyofd.ReceiptEntry(title='Мясная (трад, 23 см)',
                           qty=1,
                           price='419.00',
                           subtotal=419),
        pyofd.ReceiptEntry(title='Пицца Джона (трад, 23 см)',
                           qty=1,
                           price='419.00',
                           subtotal=419),
    ]

    def setUp(self):
        self.provider = pyofd.providers.kontur.ofdKontur()

    def test_provider_invalid(self):
        self.assertIsNone(
            self.provider.validate(fpd='0' * 10, fn='0' * 16, fd=0))

    def test_provider_minimal(self):
        self.assertIsNotNone(
            self.provider.validate(fpd='1753141947',
                                   fn='8710000101500109',
                                   fd=3250))

    def test_valid_parse(self):
        result = self.provider.validate(fpd='1753141947',
                                        fn='8710000101500109',
                                        fd=3250)
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_provider(self):
        receipt = pyofd.OFDReceipt(fpd='1753141947',
                                   fn='8710000101500109',
                                   fd=3250)

        result = receipt.load_receipt()

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)
예제 #6
0
    def _parse_entry(entry):
        try:
            title = entry.find_class('vaucher__text_col_name')[0].text
            quantity = entry.find_class('vaucher__text_col_count')[0].text
            price = _strip_currency(
                entry.find_class('vaucher__text_col_cost')[0].text)
            subtotal = _strip_currency(
                entry.find_class('vaucher__text_col_sum')[0].text)

            return pyofd.ReceiptEntry(title=title,
                                      price=price,
                                      qty=quantity,
                                      subtotal=subtotal)
        except:
            return None
예제 #7
0
    def _parse_entry(entry):
        try:
            rows = entry.findall('tr')

            title = rows[0].xpath('.//span')[0].text
            quantity = rows[1].xpath('.//span')[0].text
            price = rows[1].xpath('.//span')[1].text
            subtotal = rows[3].xpath('.//span')[1].text

            return pyofd.ReceiptEntry(title=title,
                                      price=price,
                                      qty=quantity,
                                      subtotal=subtotal)
        except:
            return None
예제 #8
0
    def _parse_entry(entry):
        try:
            rows = entry.find_class('check-col-right')

            title = entry.getchildren()[0].text.strip()

            qty_and_price = [item for item in rows[0].text.split(' ') if item]
            quantity = qty_and_price[0]
            price = qty_and_price[2]
            subtotal = rows[-1].text

            return pyofd.ReceiptEntry(title=title,
                                      price=price,
                                      qty=quantity,
                                      subtotal=subtotal)
        except:
            return None
예제 #9
0
class FirstOFDTest(unittest.TestCase):
    valid_receipt_items = [
        pyofd.ReceiptEntry(title='ТРК -  3    A98',
                           qty='41.63',
                           price='46.80',
                           subtotal='1948.28'),
    ]

    def setUp(self):
        self.provider = pyofd.providers.first_ofd.ofd1OFD()

    def test_provider_invalid(self):
        self.assertIsNone(self.provider.validate(fpd=0, fn=0, fd=0))

    def test_provider_minimal(self):
        self.assertIsNotNone(
            self.provider.validate(fpd=2819037689,
                                   fn=8710000100828376,
                                   fd=87242))

    def test_valid_parse(self):
        result = self.provider.validate(fpd=2819037689,
                                        fn=8710000100828376,
                                        fd=87242)
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_provider(self):
        receipt = pyofd.OFDReceipt(fpd=2819037689,
                                   fn=8710000100828376,
                                   fd=87242)

        result = receipt.load_receipt()

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)
예제 #10
0
class TaxcomTest(unittest.TestCase):
    valid_receipt_items = [
            pyofd.ReceiptEntry(title='Яйцо шок KINDER SURPRISE мол шок 20г'    , qty=2, price='69.89', subtotal='139.78'),
            pyofd.ReceiptEntry(title='Молоко ПРОСТОКВАШ отб ПЭТ 3,4-4,5% 930мл', qty=2, price='76.99', subtotal='153.98'),
            pyofd.ReceiptEntry(title='Гот завтрак NESTLE Nesquik пак 250г'     , qty=2, price='98.99', subtotal='197.98'),
            pyofd.ReceiptEntry(title='Морковь мытая п/э 1000г'                 , qty=1, price='39.99', subtotal='39.99'),
            pyofd.ReceiptEntry(title='Салат дуболистный зеленый в горшочке 1шт', qty=1, price='49.99', subtotal='49.99'),
            pyofd.ReceiptEntry(title='Сырок глаз АЛЕКСАНДРОВ мол шок ван26%50г', qty=7, price='39.91', subtotal='279.37'),
            pyofd.ReceiptEntry(title='Колбаса ПИТ ПРОДУКТ Докт вар ГОСТ400г'   , qty=1, price='268.99', subtotal='268.99'),
            pyofd.ReceiptEntry(title='Журнал За рулем'                         , qty=1, price='99.99', subtotal='99.99'),
            pyofd.ReceiptEntry(title='Хлеб КАРАВАЙ Столовый рж-пш полов 375г'  , qty=1, price='30.89', subtotal='30.89'),
            pyofd.ReceiptEntry(title='Батон КАРАВАЙ Наше солныш нарезн рез195' , qty=1, price='31.89', subtotal='31.89'),
            pyofd.ReceiptEntry(title='Конц-т пищ СУПЕРСУП горох с бекон 70г'   , qty=2, price='36.59', subtotal='73.18'),
            pyofd.ReceiptEntry(title='Суп б/п MAGGI Звезд сух/, обогащ.жел.54г', qty=2, price='15.99', subtotal='31.98'),
            pyofd.ReceiptEntry(title='Чай ПРИНЦЕССА КАНДИ Медиум лист. 200г'   , qty=1, price='88.99', subtotal='88.99'),
        ]

    def setUp(self):
        self.provider = pyofd.providers.taxcom.ofdTaxcom()

    def test_provider_invalid(self):
        self.assertIsNone(self.provider.validate(fpd=0, total=0))

    def test_provider_minimal(self):
        self.assertIsNotNone(self.provider.validate(fpd=1027455652, total=1487))

    def test_valid_parse(self):
        result = self.provider.validate(fpd=1027455652, total=1487)
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_full_parse(self):
        result = self.provider.validate(fpd=1027455652, total=1487)
        self.assertIsNotNone(result)
        self.assertEqual('ООО "Лента"', result.seller_name)
        self.assertEqual('197022, Санкт-Петербург, пр. Чкаловский, д. 50, ЛИТ.Б.', result.seller_address)
        self.assertEqual('7814148471', result.inn)
        self.assertEqual(Decimal('1487.00'), result.total)
        self.assertEqual('8710000101263672', result.fn)
        self.assertEqual(9960, result.fd)
        self.assertEqual('1027455652', result.fpd)
        self.assertEqual(43, result.shift_no)
        self.assertEqual(78, result.receipt_no)
        self.assertEqual('Кудаева Герта Харитоновна', result.cashier)
        self.assertEqual('0001482558031668', result.rn_kkt)
        self.assertEqual(datetime(year=2018, month=1, day=7, hour=14, minute=51), result.purchase_date)

    def test_provider(self):
        receipt = pyofd.OFDReceipt(fpd=1027455652, total=1487)

        result = receipt.load_receipt()

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)
예제 #11
0
class NalogRuTest(unittest.TestCase):
    valid_receipt_items = [
        pyofd.ReceiptEntry(title='Салат"Новый русский"', qty=1, price=79 , subtotal=79 ),
        pyofd.ReceiptEntry(title='Бульон мал'          , qty=1, price=44 , subtotal=44 ),
        pyofd.ReceiptEntry(title='Рулетик куриный'     , qty=1, price=139, subtotal=139),
        pyofd.ReceiptEntry(title='Макароны'            , qty=1, price=45 , subtotal=45 ),
        pyofd.ReceiptEntry(title='Компот'              , qty=1, price=20 , subtotal=20 ),
        pyofd.ReceiptEntry(title='Хлеб'                , qty=1, price=3  , subtotal=3  ),
    ]

    @classmethod
    def setUpClass(cls):
        pyofd.providers.nalog.NalogRu.apiLogin = os.environ.get('PYOFD_NALOGRU_LOGIN', None)
        pyofd.providers.nalog.NalogRu.apiPassword = os.environ.get('PYOFD_NALOGRU_PASSWORD', None)

    @classmethod
    def tearDownClass(cls):
        pyofd.providers.nalog.NalogRu.apiLogin = None
        pyofd.providers.nalog.NalogRu.apiPassword = None

    def setUp(self):
        self.provider = pyofd.providers.nalog.NalogRu()

    def _skip_if_no_credentials(self):
        if pyofd.providers.nalog.NalogRu.apiLogin is None or pyofd.providers.nalog.NalogRu.apiPassword is None:
            raise unittest.SkipTest('Nalog.Ru credentials not provided')

    def test_class(self):
        self.assertEqual(self.provider.__class__, pyofd.providers.NalogRu)

    def test_provider_invalid(self):
        self._skip_if_no_credentials()
        self.assertIsNone(self.provider.validate(fpd='0'*10, rn_kkt='0'*16, inn='0'*10, fn='0'*16, fd=0, total=0,
                                                 purchase_date=datetime(year=2000, month=1, day=1, hour=0, minute=0)))

    def test_provider_minimal(self):
        self._skip_if_no_credentials()
        self.assertIsNotNone(self.provider.validate(
            fpd='2981623349', inn='7814339162', rn_kkt='0000489397013091', fn='8710000100617432', fd=7481, total=330,
            purchase_date=datetime(year=2018, month=1, day=16, hour=13, minute=11)))

    def test_receipt_exists(self):
        fields = {
            'total' : Decimal(4939.00),
            'fpd' : 4105559338,
            'fn' : 9288000100066501,
            'fd' : 37072,
            'purchase_date' : datetime(year=2018, month=11, day=24, hour=23, minute=36)
        }
        self.assertTrue(self.provider.check_exists(**fields))


    def test_valid_parse(self):
        self._skip_if_no_credentials()
        result = self.provider.validate(
            fpd='2981623349', rn_kkt='0000489397013091', inn='7814339162', fn='8710000100617432', fd=7481, total=330,
            purchase_date=datetime(year=2018, month=1, day=16, hour=13, minute=11))
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_provider(self):
        self._skip_if_no_credentials()
        receipt = pyofd.OFDReceipt(
            fpd='2981623349', rn_kkt='0000489397013091', inn='7814339162', fn='8710000100617432', fd=7481, total=330,
            purchase_date=datetime(year=2018, month=1, day=16, hour=13, minute=11))

        result = receipt.load_receipt(check_providers = self.provider)

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)
예제 #12
0
class OfdRuTest(unittest.TestCase):
    valid_receipt_items = [
        pyofd.ReceiptEntry(title='Салат"Новый русский"',
                           qty=1,
                           price=79,
                           subtotal=79),
        pyofd.ReceiptEntry(title='Бульон мал', qty=1, price=44, subtotal=44),
        pyofd.ReceiptEntry(title='Рулетик куриный',
                           qty=1,
                           price=139,
                           subtotal=139),
        pyofd.ReceiptEntry(title='Макароны', qty=1, price=45, subtotal=45),
        pyofd.ReceiptEntry(title='Компот', qty=1, price=20, subtotal=20),
        pyofd.ReceiptEntry(title='Хлеб', qty=1, price=3, subtotal=3),
    ]

    def setUp(self):
        self.provider = pyofd.providers.ofd.ofdOfdRu()

    def test_provider_invalid(self):
        self.assertIsNone(
            self.provider.validate(fpd='0' * 10,
                                   rn_kkt='0' * 16,
                                   inn='0' * 10,
                                   fn='0' * 16,
                                   fd=0))

    def test_provider_minimal(self):
        self.assertIsNotNone(
            self.provider.validate(fpd='2981623349',
                                   inn='7814339162',
                                   rn_kkt='0000489397013091',
                                   fn='8710000100617432',
                                   fd=7481))

    def test_valid_parse(self):
        result = self.provider.validate(fpd='2981623349',
                                        rn_kkt='0000489397013091',
                                        inn='7814339162',
                                        fn='8710000100617432',
                                        fd=7481)
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_provider(self):
        receipt = pyofd.OFDReceipt(fpd='2981623349',
                                   rn_kkt='0000489397013091',
                                   inn='7814339162',
                                   fn='8710000100617432',
                                   fd=7481)

        result = receipt.load_receipt()

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)

    def test_issue_1(self):
        '''
        Test case for https://github.com/sergelevin/pyofd/issues/1
        '''
        self.assertIsNotNone(
            self.provider.validate(fpd='1626880333',
                                   inn='7825439514',
                                   rn_kkt='0000520679026739',
                                   fn='8710000100767988',
                                   fd=160669))
예제 #13
0
class PlatformaTest(unittest.TestCase):
    valid_receipt_items = [
        pyofd.ReceiptEntry(title='КАРАМЕЛЬ ЧУПА ЧУПС ФРУКТОВАЯ В',
                           qty='2',
                           price='7.19',
                           subtotal='14.38'),
        pyofd.ReceiptEntry(title='БАНАНЫ ВЕС',
                           qty='1.035',
                           price='53.90',
                           subtotal='55.79'),
        pyofd.ReceiptEntry(title='КРУАССАНЫ 7 DAYS МИНИ КАКАО 30',
                           qty='1',
                           price='96.90',
                           subtotal='96.90'),
        pyofd.ReceiptEntry(title='СЫРОК-СУФЛЕ ГЛАЗИР.ВАНИЛЬ Б.Ю.',
                           qty='6',
                           price='44.90',
                           subtotal='269.40'),
        pyofd.ReceiptEntry(title='СЫРОК ГЛ. Б.Ю.АЛЕКСАНДРОВ 26%',
                           qty='1',
                           price='31.43',
                           subtotal='31.43'),
        pyofd.ReceiptEntry(title='СЫРОК ГЛ. Б.Ю.АЛЕКСАНДРОВ 26%',
                           qty='1',
                           price='31.43',
                           subtotal='31.43'),
        pyofd.ReceiptEntry(title='ДРАЖЕ ТИК ТАК МЯТА/АПЕЛЬСИН 16',
                           qty='1',
                           price='45.00',
                           subtotal='45.00'),
        pyofd.ReceiptEntry(title='ДРАЖЕ ТИК ТАК МЯТА/АПЕЛЬСИН 16',
                           qty='1',
                           price='45.00',
                           subtotal='45.00'),
        pyofd.ReceiptEntry(title='ЙОГУРТ РАСТИШКА 3% КЛУБНИКА 11',
                           qty='2',
                           price='17.99',
                           subtotal='35.98'),
        pyofd.ReceiptEntry(title='ХЛЕБ РЖАНОЙ БУЛОЧНАЯ №1 ПОДОВЫ',
                           qty='1',
                           price='14.90',
                           subtotal='14.90'),
        pyofd.ReceiptEntry(title='ХЛЕБ РЖАНОЙ НАР.415Г КР',
                           qty='1',
                           price='24.90',
                           subtotal='24.90'),
        pyofd.ReceiptEntry(title='ЯЙЦО КИНДЕР СЮРПРИЗ ИЗ МОЛОЧ.Ш',
                           qty='2',
                           price='78.90',
                           subtotal='157.80'),
    ]

    alt_valid_receipt_items = [
        pyofd.ReceiptEntry(
            title=
            'Kонструктор LEGO CITY "Грузовой вертолет исследователей джунглей',
            qty=1,
            price=1195,
            subtotal=1195.00),
        pyofd.ReceiptEntry(
            title='Kонструктор LEGO Elves "Тайная лечебница Розалин"(41187)',
            qty=1,
            price=3399,
            subtotal=3399.00),
        pyofd.ReceiptEntry(title='Пакет LEGO Medium(Medium)',
                           qty=1,
                           price=0,
                           subtotal=0),
    ]

    def setUp(self):
        self.provider = pyofd.providers.platforma.ofdPlatforma()

    def test_provider_invalid(self):
        self.assertIsNone(self.provider.validate(fpd=0, fn=0, fd=0))

    def test_provider_minimal(self):
        self.assertIsNotNone(
            self.provider.validate(fpd=504931317,
                                   fn=8710000100186516,
                                   fd=136682))

    def test_valid_parse(self):
        result = self.provider.validate(fpd=504931317,
                                        fn=8710000100186516,
                                        fd=136682)
        self.assertIsNotNone(result)
        self.assertEqual(self.valid_receipt_items, result.items)

    def test_full_parse(self):
        result = self.provider.validate(fpd=504931317,
                                        fn=8710000100186516,
                                        fd=136682)
        self.assertIsNotNone(result)
        self.assertEqual('АО "Дикси Юг" Дикси-78722', result.seller_name)
        self.assertEqual(
            '197022, г. Санкт-Петербург Каменноостровский пр-кт, д. 64, лит. А',
            result.seller_address)
        self.assertEqual('5036045205', result.inn)
        self.assertEqual(Decimal('822.91'), result.total)
        self.assertEqual('5036045205', result.inn)
        self.assertEqual('8710000100186516', result.fn)
        self.assertEqual('136682', result.fd)
        self.assertEqual('504931317', result.fpd)
        self.assertEqual(336, result.shift_no)
        self.assertEqual(233, result.receipt_no)
        self.assertEqual('КА Олейникова', result.cashier)
        self.assertEqual('0000051440037872', result.rn_kkt)
        self.assertEqual(
            datetime(year=2018, month=1, day=10, hour=17, minute=37),
            result.purchase_date)

    def test_alt_receipt(self):
        result = self.provider.validate(fpd=1154793488,
                                        fn=8710000100199134,
                                        fd=12659)
        self.assertIsNotNone(result)
        self.assertEqual(self.alt_valid_receipt_items, result.items)

    def test_provider(self):
        receipt = pyofd.OFDReceipt(fpd=504931317,
                                   fn=8710000100186516,
                                   fd=136682)

        result = receipt.load_receipt()

        self.assertEqual(True, result)
        self.assertIs(receipt.provider.__class__, self.provider.__class__)
        self.assertEqual(self.valid_receipt_items, receipt.items)