Project

General

Profile

0001-contrib.teamnet_axel-invoice-pdf-download-endpoint-8.patch

Serghei Mihai, 18 Sep 2015 02:54 PM

Download (3.74 KB)

View differences:

Subject: [PATCH] contrib.teamnet_axel: invoice pdf download endpoint (#8035)

 passerelle/contrib/teamnet_axel/models.py                         | 7 +++++++
 .../templates/passerelle/contrib/teamnet_axel/detail.html         | 6 ++++++
 passerelle/contrib/teamnet_axel/urls.py                           | 2 ++
 passerelle/contrib/teamnet_axel/views.py                          | 8 ++++++++
 4 files changed, 23 insertions(+)
passerelle/contrib/teamnet_axel/models.py
151 151
        invoices = [utils.normalize_invoice(i.attrib, family_id) for i in xml_invoices]
152 152
        return sorted(invoices, key=lambda i: i['created'], reverse=True)
153 153

  
154
    def download_invoice(self, family_id, invoice):
155
        invoice_xml = ET.Element('FACTUREPDF')
156
        ET.SubElement(invoice_xml, 'IDFAMILLE').text = family_id
157
        ET.SubElement(ET.SubElement(invoice_xml, 'FACTURES'), 'NOFACTURE').text = invoice
158
        data = self.get_data('FacturesPDF', invoice_xml)
159
        pdf = data.find('PORTAIL/PDF')
160
        return pdf.get('FILE')
154 161

  
155 162
class Link(models.Model):
156 163
    resource = models.ForeignKey(Management)
passerelle/contrib/teamnet_axel/templates/passerelle/contrib/teamnet_axel/detail.html
58 58
  <em>2345</em> {% trans 'is family identifier' %},
59 59
  <em>20150916</em> {% trans 'is invoice identifier' %}
60 60
</li>
61
<li>{% trans 'Get invoice pdf:' %}
62
  {% url 'teamnet-axel-invoice-pdf' slug=object.slug regie_id='42' invoice_id='2345-20150916' as invoice_download_url %}
63
  <a href="{{ invoice_download_url }}">
64
    {{ site_base_uri }}{{ invoice_download_url }}
65
  </a>
66
</li>
61 67
</ul>
62 68
</div>
63 69

  
passerelle/contrib/teamnet_axel/urls.py
41 41
       name='teamnet-axel-active-invoices'),
42 42
    url(r'^(?P<slug>[\w,-]+)/regie/(?P<regie_id>[\w,-]+)/invoice/(?P<invoice_id>[\w,-]+)/$', InvoiceView.as_view(),
43 43
        name='teamnet-axel-invoice'),
44
    url(r'^(?P<slug>[\w,-]+)/regie/(?P<regie_id>[\w,-]+)/invoice/(?P<invoice_id>[\w,-]+)/pdf$', InvoicePDFView.as_view(),
45
        name='teamnet-axel-invoice-pdf'),
44 46
    #url(r'^(?P<slug>[\w,-]+)/invoice-pdf/(?P<id>[\w,-]+)/$', InvoicePDFView.as_view(),
45 47
    #    name='teamnet-axel-unlink'),
46 48
    #url(r'^(?P<slug>[\w,-]+)/invoice-paid/(?P<id>[\w,-]+)/$', InvoicePayView.as_view(),
passerelle/contrib/teamnet_axel/views.py
170 170
        for invoice in invoices:
171 171
            if invoice['id'] == invoice_id:
172 172
                return invoice
173

  
174

  
175
class InvoicePDFView(FamilyView):
176

  
177
    def get_data(self, request, *args, **kwargs):
178
        family_id, invoice_id = kwargs['invoice_id'].split('-', 1)
179
        return self.object.download_invoice(family_id,
180
                        invoice_id)
173
-