invoicing: don't delete cancellation reason used on credit (#89810)
gitea/lingo/pipeline/head This commit looks good
Details
gitea/lingo/pipeline/head This commit looks good
Details
This commit is contained in:
parent
904203c808
commit
3b3dcf1c7f
|
@ -27,7 +27,7 @@
|
|||
{% for reason in invoice_reason_list %}
|
||||
<li>
|
||||
<a href="{% url 'lingo-manager-invoicing-invoice-cancellation-reason-edit' reason.pk %}">{{ reason }}{% if reason.disabled %}<span class="extra-info"> ({% trans "disabled" %})</span>{% endif %}</a>
|
||||
{% if not reason.invoice_set.exists %}
|
||||
{% if not reason.invoice_set.exists and not reason.credit_set.exists %}
|
||||
<a class="delete" rel="popup" href="{% url 'lingo-manager-invoicing-invoice-cancellation-reason-delete' reason.pk %}">{% trans "delete"%}</a>
|
||||
{% endif %}
|
||||
</li>
|
||||
|
|
|
@ -66,7 +66,7 @@ class InvoiceReasonDeleteView(DeleteView):
|
|||
model = InvoiceCancellationReason
|
||||
|
||||
def get_queryset(self):
|
||||
return InvoiceCancellationReason.objects.filter(invoice__isnull=True)
|
||||
return InvoiceCancellationReason.objects.filter(invoice__isnull=True, credit__isnull=True)
|
||||
|
||||
def get_success_url(self):
|
||||
return '%s#open:invoice' % reverse('lingo-manager-invoicing-cancellation-reason-list')
|
||||
|
|
|
@ -3,6 +3,7 @@ import datetime
|
|||
import pytest
|
||||
|
||||
from lingo.invoicing.models import (
|
||||
Credit,
|
||||
Invoice,
|
||||
InvoiceCancellationReason,
|
||||
Payment,
|
||||
|
@ -82,6 +83,18 @@ def test_delete_invoice_reason(app, admin_user):
|
|||
|
||||
invoice.delete()
|
||||
|
||||
credit = Credit.objects.create(
|
||||
regie=regie,
|
||||
date_publication=datetime.date(2023, 4, 21),
|
||||
cancellation_reason=invoice_reason,
|
||||
)
|
||||
|
||||
resp = app.get('/manage/invoicing/cancellation-reasons/')
|
||||
assert '/manage/invoicing/cancellation-reason/invoice/%s/delete/' % invoice_reason.pk not in resp
|
||||
app.get('/manage/invoicing/cancellation-reason/invoice/%s/delete/' % invoice_reason.pk, status=404)
|
||||
|
||||
credit.delete()
|
||||
|
||||
resp = app.get('/manage/invoicing/cancellation-reasons/')
|
||||
resp = resp.click(href='/manage/invoicing/cancellation-reason/invoice/%s/delete/' % invoice_reason.pk)
|
||||
resp = resp.form.submit()
|
||||
|
|
Loading…
Reference in New Issue