Commit a9b0eb85 authored by Patrick Kimber's avatar Patrick Kimber
parent 79a70abc
Pipeline #81359677 passed with stage
in 5 minutes and 40 seconds
......@@ -633,6 +633,17 @@ class InvoiceIssueManager(models.Manager):
invoice_issue_line.save()
return invoice_issue_line
def issues(self, invoice_date=None):
if invoice_date is None:
qs = self.model.objects.all()
else:
qs = self.model.objects.filter(invoice__invoice_date=invoice_date)
return qs
def issues_outstanding(self, invoice_date=None):
qs = self.issues(invoice_date)
return qs.exclude(confirmed=True)
class InvoiceIssue(models.Model):
"""Invoices issues.
......
......@@ -51,6 +51,74 @@ def test_init_invoice_issue_two_issues_for_one_invoice():
assert 2 == InvoiceIssueLine.objects.count()
@pytest.mark.parametrize(
"invoice_date,expect",
[
(date(2019, 1, 31), ["A"]),
(date(2019, 7, 20), ["B", "C"]),
(None, ["A", "B", "C"]),
],
)
@pytest.mark.django_db
def test_issues(invoice_date, expect):
issue_a = InvoiceIssue.objects.init_invoice_issue(
InvoiceFactory(invoice_date=date(2019, 1, 31)), "A"
)
issue_a.invoice_issue.comment = "A"
issue_a.invoice_issue.save()
# b
issue_b = InvoiceIssue.objects.init_invoice_issue(
InvoiceFactory(invoice_date=date(2019, 7, 20)), "B"
)
issue_b.invoice_issue.comment = "B"
issue_b.invoice_issue.save()
# c
issue_c = InvoiceIssue.objects.init_invoice_issue(
InvoiceFactory(invoice_date=date(2019, 7, 20)), "C"
)
issue_c.invoice_issue.comment = "C"
issue_c.invoice_issue.save()
assert set(expect) == set(
[x.comment for x in InvoiceIssue.objects.issues(invoice_date)]
)
@pytest.mark.parametrize(
"invoice_date,expect",
[
(date(2019, 1, 31), ["A"]),
(date(2019, 7, 20), ["C"]),
(None, ["A", "C"]),
],
)
@pytest.mark.django_db
def test_issues_outstanding(invoice_date, expect):
issue_a = InvoiceIssue.objects.init_invoice_issue(
InvoiceFactory(invoice_date=date(2019, 1, 31)), "A"
)
issue_a.invoice_issue.comment = "A"
issue_a.invoice_issue.save()
# b
issue_b = InvoiceIssue.objects.init_invoice_issue(
InvoiceFactory(invoice_date=date(2019, 7, 20)), "B"
)
issue_b.invoice_issue.comment = "B"
issue_b.invoice_issue.confirmed = True
issue_b.invoice_issue.save()
# c
issue_c = InvoiceIssue.objects.init_invoice_issue(
InvoiceFactory(invoice_date=date(2019, 7, 20)), "C"
)
issue_c.invoice_issue.comment = "C"
issue_c.invoice_issue.save()
assert set(expect) == set(
[
x.comment
for x in InvoiceIssue.objects.issues_outstanding(invoice_date)
]
)
@pytest.mark.django_db
def test_lines():
invoice = InvoiceFactory()
......
......@@ -982,8 +982,8 @@ class ReconcileDayView(
).order_by("invoice_date")
def _issues(self):
date = self._date()
return InvoiceIssue.objects.filter(invoice__invoice_date=date).order_by(
invoice_date = self._date()
return InvoiceIssue.objects.issues(invoice_date).order_by(
"invoice_id", "pk"
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment