0001-contrib.teamnet_axel-past-and-active-invoices-retrie.patch
passerelle/contrib/teamnet_axel/models.py | ||
---|---|---|
23 | 23 | |
24 | 24 |
from passerelle.base.models import BaseResource |
25 | 25 | |
26 |
from . import soap |
|
26 |
from . import soap, utils
|
|
27 | 27 | |
28 | 28 |
logger = logging.getLogger('passerelle.contrib.teamnet_axel') |
29 | 29 | |
... | ... | |
134 | 134 |
'enfants': enfants, |
135 | 135 |
} |
136 | 136 | |
137 |
def get_factures(self, regie_id, family_id, months=None): |
|
137 |
def get_invoices(self, regie_id, family_id, months=None): |
|
138 |
if not family_id: |
|
139 |
[] |
|
138 | 140 |
operation = 'FacturesApayerRegie' |
139 |
xml_factures = ET.Element('LISTFACTURE')
|
|
140 |
ET.SubElement(xml_factures, 'IDREGIE').text = regie_id
|
|
141 |
ET.SubElement(xml_factures, 'IDFAMILLE').text = family_id
|
|
141 |
xml_invoices = ET.Element('LISTFACTURE')
|
|
142 |
ET.SubElement(xml_invoices, 'IDREGIE').text = regie_id
|
|
143 |
ET.SubElement(xml_invoices, 'IDFAMILLE').text = family_id
|
|
142 | 144 |
if months: |
145 |
# this operation returns invoices history but also the current ones |
|
143 | 146 |
operation = 'HistoriqueFacturesRegie' |
144 |
ET.SubElement(xml_factures, 'NBMOIS').text = months
|
|
145 |
data = self.get_data(operation, xml_factures)
|
|
146 |
xml_factures = data.findall('PORTAIL/FACTURES')
|
|
147 |
if not xml_factures:
|
|
148 |
raise AxelException('PORTAIL/FACTURES empty')
|
|
149 |
factures = [dict((k.lower(), v) for k, v in i.attrib.items()) for i in xml_factures]
|
|
150 |
return {'factures': factures}
|
|
147 |
ET.SubElement(xml_invoices, 'NBMOIS').text = str(months)
|
|
148 |
data = self.get_data(operation, xml_invoices)
|
|
149 |
xml_invoices = data.findall('PORTAIL/FACTURES')
|
|
150 |
if not xml_invoices:
|
|
151 |
return []
|
|
152 |
invoices = [utils.normalize_invoice(i.attrib, family_id) for i in xml_invoices]
|
|
153 |
return sorted(invoices, key=lambda i: i['created'], reverse=True)
|
|
151 | 154 | |
152 | 155 | |
153 | 156 |
class Link(models.Model): |
passerelle/contrib/teamnet_axel/templates/passerelle/contrib/teamnet_axel/detail.html | ||
---|---|---|
37 | 37 |
<a href="{% url 'teamnet-axel-family-filtered' slug=object.slug key='key' %}" |
38 | 38 |
>{{ site_base_uri }}{% url 'teamnet-axel-family-filtered' slug=object.slug key='key' %}?NameID=...</a> |
39 | 39 |
<em>key</em> is <em>responsables</em> or <em>enfants</em></li> |
40 |
<li>{% trans 'Get family invoice list:' %} |
|
41 |
<a href="{% url 'teamnet-axel-invoices' slug=object.slug %}"> |
|
42 |
{{ site_base_uri }}{% url 'teamnet-axel-invoices' slug=object.slug %}?NameID=...&regie=...&months=... |
|
43 |
</a> |
|
40 |
<li>{% trans 'Get invoice history list:' %} |
|
41 |
{% url 'teamnet-axel-invoices-history' regie_id='42' slug=object.slug as invoices_history_url %} |
|
42 |
<a href="{{ invoices_history_url }}"> |
|
43 |
{{ site_base_uri }}{{ invoices_history_url }}?NameID=... |
|
44 |
</a> <em>42</em> {% trans 'is regie identifier' %} |
|
45 |
</li> |
|
46 |
<li>{% trans 'Get invoice list:' %} |
|
47 |
{% url 'teamnet-axel-invoices' regie_id='42' slug=object.slug as invoices_url %} |
|
48 |
<a href="{{ invoices_url }}"> |
|
49 |
{{ site_base_uri }}{{ invoices_url }}?NameID=... |
|
50 |
</a> <em>42</em> {% trans 'is regie identifier' %} |
|
44 | 51 |
</li> |
45 | 52 |
</ul> |
46 | 53 |
</div> |
passerelle/contrib/teamnet_axel/urls.py | ||
---|---|---|
35 | 35 |
name='teamnet-axel-family'), |
36 | 36 |
url(r'^(?P<slug>[\w,-]+)/family/(?P<key>[\w,-]+)/$', FamilyView.as_view(), |
37 | 37 |
name='teamnet-axel-family-filtered'), |
38 |
url(r'^(?P<slug>[\w,-]+)/invoices/$', InvoicesView.as_view(), |
|
38 |
url(r'^(?P<slug>[\w,-]+)/regie/(?P<regie_id>[\w,-]+)/invoices/history/$', HistoryInvoicesView.as_view(), |
|
39 |
name='teamnet-axel-invoices-history'), |
|
40 |
url(r'^(?P<slug>[\w,-]+)/regie/(?P<regie_id>[\w,-]+)/invoices/$', InvoicesView.as_view(), |
|
39 | 41 |
name='teamnet-axel-invoices'), |
40 | 42 |
#url(r'^(?P<slug>[\w,-]+)/invoice/(?P<id>[\w,-]+)/$', InvoiceView.as_view(), |
41 | 43 |
# name='teamnet-axel-invoice'), |
passerelle/contrib/teamnet_axel/utils.py | ||
---|---|---|
1 |
from datetime import datetime |
|
2 |
from decimal import Decimal |
|
3 | ||
4 |
def normalize_invoice(invoice, family_id): |
|
5 |
invoice['total_amount'] = Decimal(invoice['FMONTANT']) |
|
6 |
invoice['amount'] = Decimal(invoice['RESTEAPAYER']) |
|
7 |
invoice['id'] = '%s-%s' % (family_id, invoice['NOFACTURE']) |
|
8 |
invoice['display_id'] = invoice['NOFACTURE'] |
|
9 |
invoice['has_pdf'] = invoice['FPDF'] == 'O' |
|
10 |
invoice['online_payment'] = Decimal(invoice['RESTEAPAYER']) != 0 |
|
11 |
invoice['created'] = datetime.strptime(invoice['FEMISSION'], '%d/%m/%Y') |
|
12 |
invoice['label'] = invoice['FLIBELLE'] |
|
13 |
invoice['pay_limit_date'] = datetime.strptime(invoice['FECHEANCE'], '%d/%m/%Y') |
|
14 |
return invoice |
passerelle/contrib/teamnet_axel/views.py | ||
---|---|---|
135 | 135 |
else: |
136 | 136 |
return famille.get(kwargs['key']) |
137 | 137 | |
138 | ||
138 | 139 |
class InvoicesView(FamilyView): |
139 | 140 | |
140 |
def get_data(self, request, *args, **kwargs): |
|
141 |
regie = request.GET.get('regie') |
|
142 |
months = request.GET.get('months') |
|
143 |
factures = self.object.get_factures(regie, self.get_family_id(request), months) |
|
144 |
return factures |
|
141 |
def get_data(self, request, regie_id, **kwargs): |
|
142 |
return self.object.get_invoices(regie_id, self.get_family_id(request)) |
|
143 | ||
144 | ||
145 |
class HistoryInvoicesView(FamilyView): |
|
146 | ||
147 |
def get_data(self, request, regie_id, **kwargs): |
|
148 |
family_id = self.get_family_id(request) |
|
149 |
past = self.object.get_invoices(regie_id, family_id, months=12) |
|
150 | ||
151 |
# exclude the active invoices from the past ones |
|
152 |
active = self.object.get_invoices(regie_id, family_id) |
|
153 |
return [p for p in past if p not in active] |
|
145 |
- |