Skip to content

Commit 62053da

Browse files
committed
test: invoice tests updated
1 parent 351c2a7 commit 62053da

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

tuttle/model.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -619,24 +619,14 @@ def sum(self) -> Decimal:
619619
def VAT_total(self) -> Decimal:
620620
"""Sum of VAT over all invoice items."""
621621
s = sum(item.VAT for item in self.items)
622-
return Decimal(s)
622+
return Decimal(round(s, 2))
623623

624624
@property
625625
def total(self) -> Decimal:
626626
"""Total invoiced amount."""
627627
t = self.sum + self.VAT_total
628628
return Decimal(t)
629629

630-
def generate_number(self, pattern=None, counter=None) -> str:
631-
"""Generate an invoice number"""
632-
date_prefix = self.date.strftime("%Y-%m-%d")
633-
# suffix = hashlib.shake_256(str(uuid.uuid4()).encode("utf-8")).hexdigest(2)
634-
# TODO: auto-increment suffix for invoices generated on the same day
635-
if counter is None:
636-
counter = 1
637-
suffix = f"{counter:02}"
638-
self.number = f"{date_prefix}-{suffix}"
639-
640630
@property
641631
def due_date(self) -> Optional[datetime.date]:
642632
"""Date until which payment is due."""

tuttle_tests/test_invoice.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Tests for the invoice module."""
22

33
import datetime
4+
from decimal import Decimal
45
from pathlib import Path
56

67
from tuttle import invoicing, timetracking, rendering
@@ -12,36 +13,39 @@ def test_invoice():
1213
the_invoice = Invoice(
1314
number="27B-6",
1415
date=datetime.date.today(),
15-
due_date=datetime.date.today() + datetime.timedelta(days=14),
16-
sent_date=datetime.date.today(),
1716
sent=True,
18-
paid="foo",
17+
paid=False,
1918
cancelled=False,
2019
)
2120

2221
item_1 = InvoiceItem(
2322
invoice=the_invoice,
24-
date=datetime.date.today(),
23+
start_date=datetime.date.today(),
24+
end_date=datetime.date.today(),
2525
quantity=10,
2626
unit="hours",
27-
unit_price=50,
27+
unit_price=Decimal(50),
2828
description="work work",
29-
VAT_rate=0.20,
29+
VAT_rate=Decimal(0.20),
3030
)
3131

3232
item_2 = InvoiceItem(
3333
invoice=the_invoice,
34-
date=datetime.date.today(),
34+
start_date=datetime.date.today(),
35+
end_date=datetime.date.today(),
3536
quantity=10,
3637
unit="hours",
37-
unit_price=100,
38+
unit_price=Decimal(100),
3839
description="work work",
39-
VAT_rate=0.20,
40+
VAT_rate=Decimal(0.20),
4041
)
4142

42-
assert the_invoice.sum == 1500
43-
assert the_invoice.VAT_total == 300
44-
assert the_invoice.total == 1800
43+
assert item_1.invoice == the_invoice
44+
assert item_2.invoice == the_invoice
45+
46+
assert the_invoice.sum == Decimal(1500)
47+
assert the_invoice.VAT_total == Decimal(300)
48+
assert the_invoice.total == Decimal(1800)
4549

4650

4751
def test_generate_invoice(

tuttle_tests/test_model.py

-16
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,6 @@ def test_model_creation():
6464
pass
6565

6666

67-
def test_user():
68-
user = model.User(
69-
name="Archibald Tuttle",
70-
subtitle="Heating Engineer",
71-
email="harry@tuttle.com",
72-
)
73-
74-
icloud_account = model.ICloudAccount(
75-
user_name=user.email,
76-
)
77-
78-
user.icloud_account = icloud_account
79-
80-
assert icloud_account.user.name == "Archibald Tuttle"
81-
82-
8367
class TestUser:
8468
"""Tests for the User model."""
8569

0 commit comments

Comments
 (0)