Skip to content

Commit 8f2cd41

Browse files
authored
Merge branch 'main' into 353-bug-ui-paid-should-not-be-available-if-invoice-is-not-final
2 parents 66030f5 + 59749af commit 8f2cd41

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

invoice/models.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from decimal import Decimal
55
from functools import reduce
66
from math import isnan, isinf
7-
from typing import Dict
7+
from typing import Dict, List
88

99
try:
1010
from warnings import deprecated
@@ -186,8 +186,10 @@ def save(self, *args, **kwargs):
186186
super().save(*args, **kwargs)
187187

188188
@property
189-
def items(self):
190-
"""Get list of invoice items."""
189+
def items(self) -> List['InvoiceItem']:
190+
"""Get list of invoice items. Returns empty list if the invoice is not saved yet."""
191+
if self.pk is None:
192+
return []
191193
return list(self.invoiceitem_set.all())
192194

193195
@property

invoice/tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,12 @@ def test_tax_amount_strings_exclude_zero_rate(self):
10781078
tax=Decimal('0'))
10791079
self.assertEqual(invoice.tax_amount_strings, {'19%': '19.00 EUR'})
10801080

1081+
def test_invoice_items_without_save(self):
1082+
invoice = Invoice(invoice_number=1, vendor=Vendor.objects.first(),
1083+
customer=Customer.objects.first(), date=now())
1084+
self.assertEqual(len(invoice.items), 0)
1085+
1086+
10811087
class InvoicePDFViewTestCase(TestCase):
10821088
@classmethod
10831089
def setUpClass(cls):

0 commit comments

Comments
 (0)