Exemple #1
0
def collectByTimespan(start, end):
    # print(start + " " + end)
    db = sqlite()
    purchases = db.getPurchasesByTimespan(start, end)
    collection = ReceiptCollection(purchases)
    collection.collect_items()
    collection.totalize_categories()
    return collection
def test_category_prices(purchase_list_fixture):
    rc = ReceiptCollection(purchase_list_fixture)
    rc.collect_items()
    assert round(rc.categories[''][0], 2) == 30.83
    assert round(rc.categories['Zubrot'][0], 2) == 1.69
    assert round(rc.categories['Mehl'][0], 2) == 3.98
    assert round(rc.categories['Kochzutaten'][0], 2) == 4.38
    assert round(rc.categories['Obst'][0], 2) == 5.20
    assert round(rc.categories['Gewürze'][0], 2) == 10.77
def test_category_prices(purchase_list_fixture):
    rc = ReceiptCollection(purchase_list_fixture)
    rc.collect_items()
    assert round(rc.categories[''][0], 2) == 30.83
    assert round(rc.categories['Zubrot'][0], 2) == 1.69
    assert round(rc.categories['Mehl'][0], 2) == 3.98
    assert round(rc.categories['Kochzutaten'][0], 2) == 4.38
    assert round(rc.categories['Obst'][0], 2) == 5.20
    assert round(rc.categories['Gewürze'][0], 2) == 10.77
def test_categories(purchase_list_fixture):
    receipt_collection = ReceiptCollection(purchase_list_fixture)
    receipt_collection.collect_items()
    assert sorted(['Zubrot',
                   '',
                   'Mehl',
                   'Kochzutaten',
                   'Obst',
                   'Gewürze'
                   ]) == sorted(receipt_collection.categories.keys())
Exemple #5
0
def test_category_correct():
    rC = ReceiptCollection()
    rC.category_dict.item_category_dict = {
        'Pfand': 'Pfand',
        'Pesto': 'Pesto',
        'Parmesan': 'Käse',
        'Heumilch': 'Milch',
        'Milch': 'Milch',
    }
    rC.check_category('Milch', 'Heumilch')
    assert not rC.unsane_categories
Exemple #6
0
def test_category_missing():
    rC = ReceiptCollection()
    rC.category_dict.item_category_dict = {
        'Pfand': 'Pfand',
        'Pesto': 'Pesto',
        'Parmesan': 'Käse',
        'Heumilch': 'Milch',
        'Milch': 'Milch',
    }
    rC.check_category('', 'Heumilch')
    assert rC.unsane_categories[0] == ('Heumilch', '', 'Milch')
def test_items_in_categories(purchase_list_fixture):
    rc = ReceiptCollection(purchase_list_fixture)
    rc.collect_items()
    assert sorted(rc.categories[''][1]) == sorted([
        'Kakaopulver', 'Seidentofu', 'Sesam', 'Cashewbruch', 'Datteln',
        'Walnusskerne'
    ])
    assert sorted(rc.categories['Zubrot'][1]) == sorted(['Blanc de Pomm'])
    assert sorted(rc.categories['Gewürze'][1]) == sorted(
        ['Safranfäden', 'Vanillepulver', 'Basilikum, frisch'])
    assert sorted(rc.categories['Mehl'][1]) == sorted(['Roggenmehl'])
    assert sorted(rc.categories['Kochzutaten'][1]) == sorted(['Risotto'])
    assert sorted(rc.categories['Obst'][1]) == sorted(
        ['Bananen', 'Roggenmehl'])
def test_items_in_categories(purchase_list_fixture):
    rc = ReceiptCollection(purchase_list_fixture)
    rc.collect_items()
    assert sorted(rc.categories[''][1]) == sorted(['Kakaopulver',
                                                   'Seidentofu',
                                                   'Sesam',
                                                   'Cashewbruch',
                                                   'Datteln',
                                                   'Walnusskerne'])
    assert sorted(rc.categories['Zubrot'][1]) == sorted(['Blanc de Pomm'])
    assert sorted(rc.categories['Gewürze'][1]) == sorted(['Safranfäden',
                                                          'Vanillepulver',
                                                          'Basilikum, frisch'])
    assert sorted(rc.categories['Mehl'][1]) == sorted(['Roggenmehl'])
    assert sorted(rc.categories['Kochzutaten'][1]) == sorted(['Risotto'])
    assert sorted(rc.categories['Obst'][1]) == sorted(['Bananen',
                                                       'Roggenmehl'])
Exemple #9
0
def test_create_ledger():
    receipt_collection = ReceiptCollection()
    Position = namedtuple('item',
                          ['name', 'category', 'price', 'count', 'weight'])
    testPurchaseOne = Purchase('2015-11-29', "TestShopOne")
    testPurchaseOne.positions.append(
        Position('foo', 'category:subcategory1', 1.23, '', ''))
    receipt_collection.purchases.append(testPurchaseOne)
    testPurchaseTwo = Purchase('2015-11-28',
                               "TestShopTwo",
                               payment_method="Giro")
    testPurchaseTwo.positions.append(
        Position('bar', 'category:subcategory2', 4.56, '', ''))
    testPurchaseTwo.positions.append(
        Position('foo', 'category:subcategory1', 2.46, '2', ''))
    receipt_collection.purchases.append(testPurchaseTwo)
    testPurchaseThree = Purchase('2015-11-30',
                                 "TestShopThree",
                                 payment_method="Giro")
    testPurchaseThree.positions.append(
        Position('bar', 'category:subcategory2', 4.56, '', ''))
    testPurchaseThree.positions.append(
        Position('foo', 'category:subcategory1', 2.46, '2', ''))
    receipt_collection.purchases.append(testPurchaseThree)

    actual_output = receipt_collection.get_ledger()
    expected_output = "2015-11-28 TestShopTwo\n"
    expected_output += "  Aktiva:Giro  -7.02\n"
    expected_output += "  category:subcategory2  4.56\n"
    expected_output += "  category:subcategory1  2.46\n"
    expected_output += "\n"
    expected_output += "2015-11-29 TestShopOne\n"
    expected_output += "  Aktiva:Portmonaie  -1.23\n"
    expected_output += "  category:subcategory1  1.23\n"
    expected_output += "\n"
    expected_output += "2015-11-30 TestShopThree\n"
    expected_output += "  Aktiva:Giro  -7.02\n"
    expected_output += "  category:subcategory2  4.56\n"
    expected_output += "  category:subcategory1  2.46\n"
    expected_output += "\n"
    assert expected_output == actual_output
Exemple #10
0
def collectByTimespan(start, end):
    # print(start + " " + end)
    db = sqlite()
    purchases = db.getPurchasesByTimespan(start, end)
    collection = ReceiptCollection(purchases)
    collection.collect_items()
    collection.totalize_categories()
    return collection
Exemple #11
0
parser.add_argument("-l", "--ledger", action="store_true",
                    help="show receipts in ledger format ")
parser.add_argument("-d", "--date", metavar=('date'), default="1900-01-01",
                    help="show only output from this day on")

args = parser.parse_args()

parser_args = {}

if args.categories_file:
    cat_dict = ItemCategoryDict(path=args.categories_file)
    parser_args['category_dictionary'] = cat_dict

with ReceiptParser(**parser_args) as p:
    purchases = p.read_file(args.receipts_file)
rc = ReceiptCollection(purchases)
rc.collect_items()

if args.categories:
    for key in rc.categories:
        print key
elif args.show_null:
    print 'Items without category:'
    for item in rc.categories[''][1]:
        print item
elif args.show_category is not None:
    print 'Items in category ' + args.show_category + ':'
    for item in rc.categories[args.show_category][1]:
        print item
elif args.check_sanity:
    print "The following items are in more than one category or their price is missing:"
Exemple #12
0
                    "--date",
                    metavar=('date'),
                    default="1900-01-01",
                    help="show only output from this day on")

args = parser.parse_args()

parser_args = {}

if args.categories_file:
    cat_dict = ItemCategoryDict(path=args.categories_file)
    parser_args['category_dictionary'] = cat_dict

with ReceiptParser(**parser_args) as p:
    purchases = p.read_file(args.receipts_file)
rc = ReceiptCollection(purchases)
rc.collect_items()

if args.categories:
    for key in rc.categories:
        print key
elif args.show_null:
    print 'Items without category:'
    for item in rc.categories[''][1]:
        print item
elif args.show_category is not None:
    print 'Items in category ' + args.show_category + ':'
    for item in rc.categories[args.show_category][1]:
        print item
elif args.check_sanity:
    print "The following items are in more than one category or their price is missing:"
Exemple #13
0
def test_category_both_missing():
    rC = ReceiptCollection()
    rC.check_category('', 'Testitem')
    assert not rC.unsane_categories
Exemple #14
0
def test_category_stored_missing():
    rC = ReceiptCollection()
    rC.check_category('Testcategory', 'Testitem')
    assert rC.unsane_categories[0] == ('Testitem', 'Testcategory', '')
def test_collect_unsane_items(purchase_list_fixture):
    rc = ReceiptCollection(purchase_list_fixture)
    rc.collect_items()
    assert rc.unsane_items == ['Item without Price', 'Roggenmehl']
def test_categories(purchase_list_fixture):
    receipt_collection = ReceiptCollection(purchase_list_fixture)
    receipt_collection.collect_items()
    assert sorted(['Zubrot', '', 'Mehl', 'Kochzutaten', 'Obst',
                   'Gewürze']) == sorted(receipt_collection.categories.keys())
def test_collect_unsane_items(purchase_list_fixture):
    rc = ReceiptCollection(purchase_list_fixture)
    rc.collect_items()
    assert rc.unsane_items == ['Item without Price', 'Roggenmehl']