eo_facture: postfix invoice cancelation filenames (#61117)
This commit is contained in:
parent
29a91b6638
commit
57c03d29aa
|
@ -10,7 +10,7 @@
|
|||
{% if original.contrat %}
|
||||
<li><a href="{% url "admin:eo_facture_contrat_change" original.contrat.id %}" class="historylink">Contrat</a></li>
|
||||
{% endif %}
|
||||
<li><a href="{{history_url}}../view_pdf/{{ original.code }}.pdf">Imprimer</a></li>
|
||||
<li><a href="{{history_url}}../view_pdf/{{ original.code }}{% if original.annulation %}-AVOIR{% endif %}.pdf">Imprimer</a></li>
|
||||
{% if original.client.chorus_structure and not original.proforma %}
|
||||
<li><a href="{% url "admin:eo_facture_facture_send_to_chorus" original.id %}">Envoyer à Chorus</a></li>
|
||||
{% endif %}
|
||||
|
|
|
@ -24,6 +24,7 @@ from django.contrib import messages
|
|||
from django.contrib.admin.models import LogEntry
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.shortcuts import get_object_or_404, redirect
|
||||
from django.utils.encoding import force_text
|
||||
|
||||
from eo_gestion.chorus.chorus import push_to_chorus
|
||||
|
||||
|
@ -47,7 +48,12 @@ def facture_pdf(request, facture_id):
|
|||
if hasattr(settings, 'FACTURE_DIR'):
|
||||
filename = os.path.join(
|
||||
settings.FACTURE_DIR,
|
||||
'%s-%s.pdf' % (facture.code(), facture.contrat.client.nom.encode('utf8')),
|
||||
'%s-%s%s.pdf'
|
||||
% (
|
||||
facture.code(),
|
||||
force_text(facture.contrat.client.nom),
|
||||
'-AVOIR' if facture.annulation else '',
|
||||
),
|
||||
)
|
||||
with open(filename, 'wb') as fd:
|
||||
fd.write(pdf)
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import io
|
||||
import os
|
||||
import tempfile
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import facturx
|
||||
|
@ -166,6 +168,50 @@ def test_facture_avoir(app):
|
|||
]
|
||||
|
||||
|
||||
def test_facture_filename(app, settings):
|
||||
tmpdir = tempfile.mkdtemp('barba-test')
|
||||
settings.FACTURE_DIR = tmpdir
|
||||
facture = [x for x in Facture.objects.all() if x.code() == 'F20190137'][0]
|
||||
|
||||
response = app.get("/eo_facture/facture/").follow()
|
||||
response.form.set("username", "admin")
|
||||
response.form.set("password", "admin")
|
||||
homepage = response.form.submit().follow()
|
||||
|
||||
# facture F20190137
|
||||
factures_page = homepage.click("Factures")
|
||||
facture_0137_page = factures_page.click(facture.code())
|
||||
assert (
|
||||
'/view_pdf/F20190137.pdf'
|
||||
in [li.a['href'] for li in facture_0137_page.html.find_all('li') if li.text == 'Imprimer'][0]
|
||||
)
|
||||
app.get("/eo_facture/facture/%s/view_pdf/" % facture.id)
|
||||
assert os.path.exists(os.path.join(tmpdir, "F20190137-c3f42bb0d75d379.pdf"))
|
||||
|
||||
# facture avoir proformat
|
||||
facture_avoir_page = facture_0137_page.click("Annuler")
|
||||
facture_avoir_page = facture_avoir_page.follow()
|
||||
facture_avoir = facture.factures_avoir.first()
|
||||
assert (
|
||||
'/view_pdf/Facture proforma du 2019-10-09-AVOIR.pdf'
|
||||
in [li.a['href'] for li in facture_avoir_page.html.find_all('li') if li.text == 'Imprimer'][0]
|
||||
)
|
||||
app.get("/eo_facture/facture/%s/view_pdf/" % facture_avoir.id)
|
||||
assert os.path.exists(os.path.join(tmpdir, "Facture proforma du 2019-10-09-c3f42bb0d75d379-AVOIR.pdf"))
|
||||
|
||||
# facture avoir
|
||||
facture_avoir_page.form.fields['proforma'][0].checked = False
|
||||
facture_avoir_page = facture_avoir_page.form.submit('_continue')
|
||||
facture_avoir_page = facture_avoir_page.follow()
|
||||
facture_avoir = facture.factures_avoir.first()
|
||||
assert (
|
||||
'/view_pdf/F20190237-AVOIR.pdf'
|
||||
in [li.a['href'] for li in facture_avoir_page.html.find_all('li') if li.text == 'Imprimer'][0]
|
||||
)
|
||||
app.get("/eo_facture/facture/%s/view_pdf/" % facture_avoir.id)
|
||||
assert os.path.exists(os.path.join(tmpdir, "F20190237-c3f42bb0d75d379-AVOIR.pdf"))
|
||||
|
||||
|
||||
def test_facture_pdf(app):
|
||||
facture = Facture.objects.get(
|
||||
client__nom='c3f42bb0d75d379', contrat__intitule='1da9dc528d5c7191bc87c7', ordre=137
|
||||
|
|
Loading…
Reference in New Issue