eo_facture: display original on invoice cancelation PDF (#36633)

This commit is contained in:
Nicolas Roche 2022-01-31 18:30:54 +01:00
parent 0f95d6016d
commit 29a91b6638
2 changed files with 145 additions and 0 deletions

View File

@ -10,6 +10,12 @@
<body>
<div id="date"><table><tr id="code"><td class="col1">Facture</td>{% if facture.proforma %}<td class="col2">proforma</td>{% else %}
<td class="col2">{{facture.code}}</td>{% endif %}</tr>
{% if facture.annulation %}
<tr id="code">
<td class="col1">Annule</td>
<td class="col2">{% if facture.annulation.proforma %}proforma{% else %}{{ facture.annulation.code }}{% endif %}</td>
</tr>
{% endif %}
<tr><td class="col1">Date</td><td class="col2">{{ facture.emission|date:'d/m/Y' }}</td></tr>
<tr><td class="col1">Échéance</td><td class="col2">{{ facture.echeance|date:'d/m/Y' }}</td></tr></table></div>

View File

@ -20,6 +20,7 @@ import xml.etree.ElementTree as ET
import facturx
import pytest
from django.contrib.auth import get_user_model
from weasyprint import HTML
from eo_gestion.eo_facture.models import Facture
@ -163,3 +164,141 @@ def test_facture_avoir(app):
],
],
]
def test_facture_pdf(app):
facture = Facture.objects.get(
client__nom='c3f42bb0d75d379', contrat__intitule='1da9dc528d5c7191bc87c7', ordre=137
)
def helper(root):
tag = root.tag.split('}')[-1]
if len(root) == 0:
return [tag, root.text or '']
else:
return [tag] + [helper(node) for node in root]
# facture F20190137
facture_html = HTML(string=facture.html())
root = facture_html.etree_element
facture_content = helper(root)
assert facture_content == [
'html',
['head', ['meta', ''], ['title', 'Facture F20190137 - 95e0eb4429394cd2'], ['meta', ''], ['link', '']],
[
'body',
[
'div',
[
'table',
[
'tbody',
['tr', ['td', 'Facture'], ['td', 'F20190137']],
['tr', ['td', 'Date'], ['td', '09/10/2019']],
['tr', ['td', 'Échéance'], ['td', '23/11/2019']],
],
],
],
[
'div',
['img', ''],
[
'div',
'\nSociété Coopérative et Participative\n'
'SARL au capital variable de 15200 €\n'
'169 rue du château\n'
'75014 PARIS\n'
'FRANCE\n\n'
'Tél : 01 43 35 01 35\n'
'Email : gerant@entrouvert.com\n'
'Web : https://www.entrouvert.com\n'
'RCS : Paris\n'
'NAF/APE : 6201Z\n'
'SIRET : 443 170 139 00036\n'
'Numéro TVA : FR 08443170139',
],
],
['div', ['strong', 'c3f42bb0d75d379'], ['br', '']],
[
'div',
['div', ['h1', '95e0eb4429394cd2']],
['div', ['p', 'e8078180ca3a563dd45070362a6a102e']],
[
'table',
[
'thead',
[
'tr',
['td', 'Description'],
['td', 'Quantité'],
['td', 'Prix unitaire'],
['td', 'Prix HT'],
],
],
[
'tbody',
[
'tr',
['td', '503aa5f7b148f6a106eda9274d5130c1'],
['td', '1,00'],
['td', '800,85'],
['td', '800,85'],
],
],
[
'tfoot',
['tr', ['td', 'Sous-total :'], ['td', '800,85']],
['tr', ['td', 'Total TVA (à 20,00 %) :'], ['td', '160,17']],
['tr', ['td', 'Total TTC :'], ['td', '961,02']],
],
],
['p', "Paiement total de 961,02 € à verser au nom d'Entr'ouvert."],
['p', 'Mode de paiement : virement'],
],
[
'div',
[
'div',
'Domiciliation bancaire : BP RIVES MAINE\n'
'BIC : CCBPFRPPMTG\n'
'IBAN : FR76 1020 7000 9104 0910 0252 059\n'
'Code étab. : 10207 Code guichet : 00091 Numéro de compte : 04091002520 Clé RIB : 59',
],
['div', ['img', '']],
['div', ['a', 'https://www.entrouvert.com/fr/conditions-generales-de-vente/']],
],
],
]
# facture avoir
User = get_user_model()
creator = User.objects.get(username='admin')
facture_avoir = facture.cancel(creator)
facture_avoir.proforma = False
facture_avoir.save()
facture_avoir_html = HTML(string=facture_avoir.html())
root_avoir = facture_avoir_html.etree_element
facture_avoir_content = helper(root_avoir)
assert facture_avoir_content[2][1][1][1] == [
'tbody',
['tr', ['td', 'Facture'], ['td', 'F20190237']],
['tr', ['td', 'Annule'], ['td', 'F20190137']],
['tr', ['td', 'Date'], ['td', '09/10/2019']],
['tr', ['td', 'Échéance'], ['td', '23/11/2019']],
]
# facture avoir proformat
facture.proforma = True
facture.save()
facture_avoir.proforma = True
facture_avoir.save()
facture_avoir_html = HTML(string=facture_avoir.html())
root_avoir = facture_avoir_html.etree_element
facture_avoir_content = helper(root_avoir)
assert facture_avoir_content[2][1][1][1] == [
'tbody',
['tr', ['td', 'Facture'], ['td', 'proforma']],
['tr', ['td', 'Annule'], ['td', 'proforma']],
['tr', ['td', 'Date'], ['td', '09/10/2019']],
['tr', ['td', 'Échéance'], ['td', '23/11/2019']],
]