Exemplo n.º 1
0
def main(argv):
    arguments = parser.parse_args(argv)
    receipt_fields = {
        k: getattr(arguments, k)
        for k in fields
        if hasattr(arguments, k) and getattr(arguments, k) is not None
    }
    date_time_str = getattr(arguments, 'purchase_date', None)
    if date_time_str is not None:
        receipt_fields['purchase_date'] = parse_date_time(date_time_str)
    url = getattr(arguments, 'url', None)
    if url is not None:
        receipt_fields.update(parse_url(url))

    receipt = pyofd.OFDReceipt(**receipt_fields)
    result = receipt.load_receipt()

    if not result:
        sys.stderr.write('Receipt not found')
        return 1

    with smart_open(arguments.out_file_name) as out:
        for entry in receipt.items:
            out.write('{title}\t{price}\t{qty}\t{subtotal}\n'.format(
                title=entry.title,
                price=entry.price,
                qty=entry.quantity,
                subtotal=entry.subtotal))
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    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)
Exemplo n.º 4
0
    def _test_single_provider(self, provider):
        self.assertIn(provider, receipts_data)
        kwargs = receipts_data[provider]
        receipt = pyofd.OFDReceipt(**kwargs)
        result = receipt.load_receipt()

        self.assertIsNotNone(result)
        self.assertIsNotNone(receipt.provider)
        self.assertEqual(provider, receipt.provider.providerName)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    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)
Exemplo n.º 11
0
def main(argv):
    arguments = parser.parse_args(argv)
    receipt_fields = {
        k: getattr(arguments, k)
        for k in fields
        if hasattr(arguments, k) and getattr(arguments, k) is not None
    }
    date_time_str = getattr(arguments, 'purchase_date', None)
    if date_time_str is not None:
        receipt_fields['purchase_date'] = parse_date_time(date_time_str)
    url = getattr(arguments, 'url', None)
    if url is not None:
        receipt_fields.update(parse_url(url))

    nalog = NalogRu()
    nalog.apiLogin = os.environ.get('PYOFD_NALOGRU_LOGIN', None)
    nalog.apiPassword = os.environ.get('PYOFD_NALOGRU_PASSWORD', None)

    receipt = pyofd.OFDReceipt(**receipt_fields)
    result = receipt.load_receipt(
        check_providers=nalog) or receipt.load_receipt()

    if not result:
        sys.stderr.write('Receipt not found')
        return 1

    xlsx_properties = {
        'strings_to_numbers': True,
        'in_memory': True,
    }
    with xlsxwriter.Workbook(arguments.out_file_name, xlsx_properties) as out:
        worksheet = out.add_worksheet()
        data = []
        for entry in receipt.items:
            data.append(
                [entry.title, entry.price, entry.quantity, entry.subtotal])

        first_row = 3
        nrows = len(data)
        last_row = first_row + nrows - 1
        rows_spec = 'A2:D{}'.format(last_row)
        worksheet.add_table(
            rows_spec, {
                'data':
                data,
                'columns': [
                    {
                        'header': 'Item'
                    },
                    {
                        'header': 'Price'
                    },
                    {
                        'header': 'Qty'
                    },
                    {
                        'header': 'Subtotal'
                    },
                ]
            })

        worksheet.write('F2', 'Part')
        worksheet.write_formula(
            'F{}'.format(last_row + 1),
            '=SUMPRODUCT($D$3:$D${last_row},$F$3:$F${last_row})'.format(
                last_row=last_row))

        format = out.add_format({'bg_color': 'yellow'})
        #        for row in range(first_row, last_row+1):
        row_spec = '$G{row}:$Z{row}'.format(row=first_row)
        format_range = '$G{first_row}:$Z{last_row}'.format(first_row=first_row,
                                                           last_row=last_row)
        worksheet.conditional_format(
            format_range, {
                'type': 'formula',
                'criteria': '=SUM({row_spec})<>1'.format(row_spec=row_spec),
                'format': format,
            })

        for col in 'GHIJKLMNOPQRSTUVWXYZ':
            worksheet.write_formula(
                '{col}{row}'.format(col=col, row=last_row + 1),
                '=SUMPRODUCT($D$3:$D{last_row},${col}$3:${col}${last_row})'.
                format(col=col, last_row=last_row))
        worksheet.freeze_panes(2, 1)