Ejemplo n.º 1
0
 def __repr__(self):
     return ('{qty} of Refund: Total {total}\tSubtotal {subtotal}\t'
             'Tax {tax} {desc}'.format(
                 qty=self.quantity,
                 total=micro_usd_to_usd_string(self.total_refund_amount),
                 subtotal=micro_usd_to_usd_string(self.refund_amount),
                 tax=micro_usd_to_usd_string(self.refund_tax_amount),
                 desc=self.title))
Ejemplo n.º 2
0
 def __repr__(self):
     return ('{qty} of Item: Total {total}\tSubtotal {subtotal}\t'
             'Tax {tax} {desc}'.format(
                 qty=self.quantity,
                 total=micro_usd_to_usd_string(self.item_total),
                 subtotal=micro_usd_to_usd_string(self.item_subtotal),
                 tax=micro_usd_to_usd_string(self.item_subtotal_tax),
                 desc=self.title))
Ejemplo n.º 3
0
 def __repr__(self):
     return ('Order ({id}): {date} Total {total}\tSubtotal {subtotal}\t'
             'Tax {tax}\tPromo {promo}\tShip {ship}\t'
             'Items: \n{items}'.format(
                 id=self.order_id,
                 date=(self.shipment_date or self.order_date),
                 total=micro_usd_to_usd_string(self.total_charged),
                 subtotal=micro_usd_to_usd_string(self.subtotal),
                 tax=micro_usd_to_usd_string(self.tax_charged),
                 promo=micro_usd_to_usd_string(self.total_promotions),
                 ship=micro_usd_to_usd_string(self.shipping_charge),
                 items=pformat(self.items)))
Ejemplo n.º 4
0
    def __init__(self, updates, **kwargs):
        super(MintUpdatesTableModel, self).__init__(**kwargs)
        self.my_data = []
        for i, update in enumerate(updates):
            orig_trans, new_trans = update

            descriptions = []
            categories = []
            amounts = []

            if orig_trans.children:
                for trans in orig_trans.children:
                    descriptions.append('CURRENTLY: ' + trans.merchant)
                    categories.append(trans.category)
                    amounts.append(micro_usd_to_usd_string(trans.amount))
            else:
                descriptions.append('CURRENTLY: ' + orig_trans.merchant)
                categories.append(orig_trans.category)
                amounts.append(micro_usd_to_usd_string(orig_trans.amount))

            if len(new_trans) == 1:
                trans = new_trans[0]
                descriptions.append('PROPOSED: ' + trans.merchant)
                categories.append(trans.category)
                amounts.append(micro_usd_to_usd_string(trans.amount))
            else:
                for trans in reversed(new_trans):
                    descriptions.append('PROPOSED: ' + trans.merchant)
                    categories.append(trans.category)
                    amounts.append(micro_usd_to_usd_string(trans.amount))

            self.my_data.append([
                update,
                True,
                orig_trans.date.strftime('%Y/%m/%d'),
                '\n'.join(descriptions),
                '\n'.join(categories),
                '\n'.join(amounts),
                orig_trans.orders[0].order_id,
            ])

        self.header = [
            '', 'Date', 'Description', 'Category', 'Amount', 'Amazon Order'
        ]
Ejemplo n.º 5
0
 def __repr__(self):
     has_note = 'with note' if self.note else ''
     return ('Mint Trans({id}): {amount} {date} {merchant} {category} '
             '{has_note}'.format(id=self.id,
                                 amount=micro_usd_to_usd_string(
                                     self.amount),
                                 date=self.date,
                                 merchant=self.merchant,
                                 category=self.category,
                                 has_note=has_note))
Ejemplo n.º 6
0
def print_unmatched(amzn_obj):
    proposed_mint_desc = mint.summarize_title(
        [i.get_title() for i in amzn_obj.items]
        if amzn_obj.is_debit else [amzn_obj.get_title()],
        '{}{}: '.format(amzn_obj.website,
                        '' if amzn_obj.is_debit else ' refund'))
    logger.warning('{}'.format(proposed_mint_desc))
    logger.warning('\t{}\t{}\t{}'.format(
        amzn_obj.transact_date()
        if amzn_obj.transact_date() else 'Never shipped!',
        micro_usd_to_usd_string(amzn_obj.transact_amount()),
        amazon.get_invoice_url(amzn_obj.order_id)))
    logger.warning('')
Ejemplo n.º 7
0
 def _create_row(self, amzn_obj):
     proposed_mint_desc = mint.summarize_title(
         [i.get_title() for i in amzn_obj.items]
         if amzn_obj.is_debit else [amzn_obj.get_title()],
         '{}{}: '.format(amzn_obj.website,
                         '' if amzn_obj.is_debit else ' refund'))
     return [
         amzn_obj.transact_date().strftime('%m/%d/%y')
         if amzn_obj.transact_date() else 'Never shipped!',
         proposed_mint_desc,
         micro_usd_to_usd_string(amzn_obj.transact_amount()),
         amzn_obj.order_id,
     ]
Ejemplo n.º 8
0
def log_amazon_stats(items, orders, refunds):
    logger.info('\nAmazon Stats:')
    if len(orders) == 0 or len(items) == 0:
        logger.info('\tThere were not Amazon orders/items!')
        return
    logger.info('\n{} orders with {} matching items'.format(
        len([o for o in orders if o.items_matched]),
        len([i for i in items if i.matched])))
    logger.info('{} unmatched orders and {} unmatched items'.format(
        len([o for o in orders if not o.items_matched]),
        len([i for i in items if not i.matched])))

    first_order_date = min([o.order_date for o in orders])
    last_order_date = max([o.order_date for o in orders])
    logger.info('Orders ranging from {} to {}'.format(first_order_date,
                                                      last_order_date))

    per_item_totals = [i.item_total for i in items]
    per_order_totals = [o.total_charged for o in orders]

    logger.info('{} total spend'.format(
        micro_usd_to_usd_string(sum(per_order_totals))))

    logger.info('{} avg order total (range: {} - {})'.format(
        micro_usd_to_usd_string(sum(per_order_totals) / len(orders)),
        micro_usd_to_usd_string(min(per_order_totals)),
        micro_usd_to_usd_string(max(per_order_totals))))
    logger.info('{} avg item price (range: {} - {})'.format(
        micro_usd_to_usd_string(sum(per_item_totals) / len(items)),
        micro_usd_to_usd_string(min(per_item_totals)),
        micro_usd_to_usd_string(max(per_item_totals))))

    if refunds:
        first_refund_date = min(
            [r.refund_date for r in refunds if r.refund_date])
        last_refund_date = max(
            [r.refund_date for r in refunds if r.refund_date])
        logger.info('\n{} refunds dating from {} to {}'.format(
            len(refunds), first_refund_date, last_refund_date))

        per_refund_totals = [r.total_refund_amount for r in refunds]

        logger.info('{} total refunded'.format(
            micro_usd_to_usd_string(sum(per_refund_totals))))
Ejemplo n.º 9
0
 def dry_run_str(self, ignore_category=False):
     return '{} \t {} \t {} \t {}'.format(
         self.date.strftime('%m/%d/%y'),
         micro_usd_to_usd_string(self.amount),
         '--IGNORED--' if ignore_category else '{}({})'.format(
             self.category, self.category_id), self.merchant)
Ejemplo n.º 10
0
 def get_compare_tuple(self, ignore_category=False):
     """Returns a 3-tuple used to determine if 2 transactions are equal."""
     # TODO: Add the 'note' field once itemized transactions include notes.
     # Use str to avoid float cmp.
     base = (self.merchant, micro_usd_to_usd_string(self.amount), self.note)
     return base if ignore_category else base + (self.category, )
Ejemplo n.º 11
0
    def __init__(self, items, orders, refunds, **kwargs):
        super(AmazonStatsDialog, self).__init__(**kwargs)
        self.setWindowTitle('Amazon Stats for Items/Orders/Refunds')
        self.setModal(True)
        v_layout = QVBoxLayout()
        self.setLayout(v_layout)

        v_layout.addWidget(QLabel('Amazon Stats:'))
        if len(orders) == 0 or len(items) == 0:
            v_layout.addWidget(QLabel('There were not Amazon orders/items!'))

            close_button = QPushButton('Close')
            v_layout.addWidget(close_button)
            close_button.clicked.connect(self.close)
            return

        v_layout.addWidget(
            QLabel('\n{} orders with {} matching items'.format(
                len([o for o in orders if o.items_matched]),
                len([i for i in items if i.matched]))))
        v_layout.addWidget(
            QLabel('{} unmatched orders and {} unmatched items'.format(
                len([o for o in orders if not o.items_matched]),
                len([i for i in items if not i.matched]))))

        first_order_date = min([o.order_date for o in orders])
        last_order_date = max([o.order_date for o in orders])

        v_layout.addWidget(
            QLabel('Orders ranging from {} to {}'.format(
                first_order_date, last_order_date)))

        per_item_totals = [i.item_total for i in items]
        per_order_totals = [o.total_charged for o in orders]

        v_layout.addWidget(
            QLabel('{} total spend'.format(
                micro_usd_to_usd_string(sum(per_order_totals)))))
        v_layout.addWidget(
            QLabel('{} avg order total (range: {} - {})'.format(
                micro_usd_to_usd_string(sum(per_order_totals) / len(orders)),
                micro_usd_to_usd_string(min(per_order_totals)),
                micro_usd_to_usd_string(max(per_order_totals)))))
        v_layout.addWidget(
            QLabel('{} avg item price (range: {} - {})'.format(
                micro_usd_to_usd_string(sum(per_item_totals) / len(items)),
                micro_usd_to_usd_string(min(per_item_totals)),
                micro_usd_to_usd_string(max(per_item_totals)))))

        if refunds:
            first_refund_date = min(
                [r.refund_date for r in refunds if r.refund_date])
            last_refund_date = max(
                [r.refund_date for r in refunds if r.refund_date])
            v_layout.addWidget(
                QLabel('\n{} refunds dating from {} to {}'.format(
                    len(refunds), first_refund_date, last_refund_date)))

            per_refund_totals = [r.total_refund_amount for r in refunds]

            v_layout.addWidget(
                QLabel('{} total refunded'.format(
                    micro_usd_to_usd_string(sum(per_refund_totals)))))

        close_button = QPushButton('Close')
        v_layout.addWidget(close_button)
        close_button.clicked.connect(self.close)
Ejemplo n.º 12
0
 def test_micro_usd_to_usd_string(self):
     self.assertEqual(currency.micro_usd_to_usd_string(1230040), '$1.23')
     self.assertEqual(currency.micro_usd_to_usd_string(-123000), '-$0.12')
     self.assertEqual(currency.micro_usd_to_usd_string(-1900), '$0.00')
     self.assertEqual(currency.micro_usd_to_usd_string(-10000), '-$0.01')