family: add endpoint returning users with pending invoices (#19842)
This commit is contained in:
parent
3c8df18794
commit
ac274430ea
|
@ -22,6 +22,8 @@ import shutil
|
|||
import sys
|
||||
import zipfile
|
||||
|
||||
from collections import defaultdict
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.files.storage import default_storage
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
@ -359,6 +361,16 @@ class GenericFamily(BaseResource):
|
|||
invoice.save()
|
||||
return {'data': True}
|
||||
|
||||
@endpoint(name='regie', perm='can_access', pattern='^pending_invoices_by_nameid/$')
|
||||
def get_pending_invoices_by_nameid(self, request):
|
||||
data = defaultdict(lambda: {'invoices': []})
|
||||
for i in Invoice.objects.filter(payment_date__isnull=True,
|
||||
family__resource=self,
|
||||
family__familylink__isnull=False).select_related('family').prefetch_related('family__familylink_set'):
|
||||
name_id = i.family.familylink_set.all()[0].name_id
|
||||
data[name_id]['invoices'].append(format_invoice(i))
|
||||
return {'data': data}
|
||||
|
||||
|
||||
class FamilyLink(models.Model):
|
||||
resource = models.ForeignKey('GenericFamily')
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
%PDF-1.3
|
||||
%“Œ‹ž ReportLab Generated PDF document http://www.reportlab.com
|
||||
1 0 obj
|
||||
<< /F1 2 0 R >>
|
||||
endobj
|
||||
2 0 obj
|
||||
<< /BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font >>
|
||||
endobj
|
||||
3 0 obj
|
||||
<< /Contents 7 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 6 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >>
|
||||
/Type /Page >>
|
||||
endobj
|
||||
4 0 obj
|
||||
<< /Outlines 8 0 R /PageMode /UseNone /Pages 6 0 R /Type /Catalog >>
|
||||
endobj
|
||||
5 0 obj
|
||||
<< /Author (anonymous) /CreationDate (D:20161118142737-01'00') /Creator (ReportLab PDF Library - www.reportlab.com) /Keywords () /ModDate (D:20161118142737-01'00') /Producer (ReportLab PDF Library - www.reportlab.com)
|
||||
/Subject (unspecified) /Title (untitled) /Trapped /False >>
|
||||
endobj
|
||||
6 0 obj
|
||||
<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >>
|
||||
endobj
|
||||
7 0 obj
|
||||
<< /Filter [ /ASCII85Decode /FlateDecode ] /Length 115 >>
|
||||
stream
|
||||
GapQh0E=F,0U\H3T\pNYT^QKk?tc>IP,;W#U1^23ihPEM_TN+I0SHG`2GgV30Mi%s<R>\X9J.bG8l[Q%1GCR<2Dhm"e5Q^q;@(YOlVZU%!W]g$'Cu~>endstream
|
||||
endobj
|
||||
8 0 obj
|
||||
<< /Count 0 /Type /Outlines >>
|
||||
endobj
|
||||
xref
|
||||
0 9
|
||||
0000000000 65535 f
|
||||
0000000075 00000 n
|
||||
0000000109 00000 n
|
||||
0000000219 00000 n
|
||||
0000000426 00000 n
|
||||
0000000513 00000 n
|
||||
0000000813 00000 n
|
||||
0000000875 00000 n
|
||||
0000001085 00000 n
|
||||
trailer
|
||||
<< /ID
|
||||
% ReportLab generated PDF document -- digest (http://www.reportlab.com)
|
||||
[(\225\345b\271C#420}9\311\365k\266\254) (\225\345b\271C#420}9\311\365k\266\254)]
|
||||
/Info 5 0 R /Root 4 0 R /Size 9 >>
|
||||
startxref
|
||||
1134
|
||||
%%EOF
|
|
@ -0,0 +1,49 @@
|
|||
%PDF-1.3
|
||||
%“Œ‹ž ReportLab Generated PDF document http://www.reportlab.com
|
||||
1 0 obj
|
||||
<< /F1 2 0 R >>
|
||||
endobj
|
||||
2 0 obj
|
||||
<< /BaseFont /Helvetica /Encoding /WinAnsiEncoding /Name /F1 /Subtype /Type1 /Type /Font >>
|
||||
endobj
|
||||
3 0 obj
|
||||
<< /Contents 7 0 R /MediaBox [ 0 0 595.2756 841.8898 ] /Parent 6 0 R /Resources << /Font 1 0 R /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] >> /Rotate 0 /Trans << >>
|
||||
/Type /Page >>
|
||||
endobj
|
||||
4 0 obj
|
||||
<< /Outlines 8 0 R /PageMode /UseNone /Pages 6 0 R /Type /Catalog >>
|
||||
endobj
|
||||
5 0 obj
|
||||
<< /Author (anonymous) /CreationDate (D:20161118142737-01'00') /Creator (ReportLab PDF Library - www.reportlab.com) /Keywords () /ModDate (D:20161118142737-01'00') /Producer (ReportLab PDF Library - www.reportlab.com)
|
||||
/Subject (unspecified) /Title (untitled) /Trapped /False >>
|
||||
endobj
|
||||
6 0 obj
|
||||
<< /Count 1 /Kids [ 3 0 R ] /Type /Pages >>
|
||||
endobj
|
||||
7 0 obj
|
||||
<< /Filter [ /ASCII85Decode /FlateDecode ] /Length 115 >>
|
||||
stream
|
||||
GapQh0E=F,0U\H3T\pNYT^QKk?tc>IP,;W#U1^23ihPEM_TN+I0SHG`2GgV30Mi%s<R>\X9J.bG8l[Q%1GCR<1,_!Ke5Q^q;@(YOlVZU%!W]fE'CY~>endstream
|
||||
endobj
|
||||
8 0 obj
|
||||
<< /Count 0 /Type /Outlines >>
|
||||
endobj
|
||||
xref
|
||||
0 9
|
||||
0000000000 65535 f
|
||||
0000000075 00000 n
|
||||
0000000109 00000 n
|
||||
0000000219 00000 n
|
||||
0000000426 00000 n
|
||||
0000000513 00000 n
|
||||
0000000813 00000 n
|
||||
0000000875 00000 n
|
||||
0000001085 00000 n
|
||||
trailer
|
||||
<< /ID
|
||||
% ReportLab generated PDF document -- digest (http://www.reportlab.com)
|
||||
[(\225\345b\271C#420}9\311\365k\266\254) (\225\345b\271C#420}9\311\365k\266\254)]
|
||||
/Info 5 0 R /Root 4 0 R /Size 9 >>
|
||||
startxref
|
||||
1134
|
||||
%%EOF
|
Binary file not shown.
|
@ -315,8 +315,28 @@ def test_orleans_data_import_command():
|
|||
assert Family.objects.filter(resource=resource).count() == 18
|
||||
assert Adult.objects.all().count() == 31
|
||||
assert Child.objects.all().count() == 35
|
||||
assert Invoice.objects.filter(resource=resource).count() == 5
|
||||
assert Invoice.objects.filter(resource=resource).count() == 7
|
||||
|
||||
def test_family_pending_invoices_by_nameid_with_no_links():
|
||||
test_orleans_data_import_command()
|
||||
resource = GenericFamily.objects.get()
|
||||
links = resource.get_pending_invoices_by_nameid(None)
|
||||
assert links['data'] == {}
|
||||
|
||||
def test_family_pending_invoices_by_nameid():
|
||||
test_orleans_data_import_command()
|
||||
resource = GenericFamily.objects.get()
|
||||
family = Family.objects.get(external_id='22380')
|
||||
link = FamilyLink.objects.create(resource=resource, family=family,
|
||||
name_id='testnameid1')
|
||||
family = Family.objects.get(external_id='1228')
|
||||
link = FamilyLink.objects.create(resource=resource, family=family,
|
||||
name_id='testnameid2')
|
||||
links = resource.get_pending_invoices_by_nameid(None)
|
||||
assert len(links['data']) == 2
|
||||
for uuid, invoices in links['data'].iteritems():
|
||||
assert uuid in ('testnameid1', 'testnameid2')
|
||||
assert len(invoices) >= 1
|
||||
|
||||
def test_incorrect_orleans_data(caplog):
|
||||
filepath = os.path.join(os.path.dirname(__file__), 'data',
|
||||
|
|
Loading…
Reference in New Issue