eo_facture: forbid to cancel twice an invoice (#61117)
This commit is contained in:
parent
3b892e1d1e
commit
0f95d6016d
|
@ -406,6 +406,7 @@ class Facture(models.Model):
|
|||
|
||||
def cancel(self, creator):
|
||||
assert not self.annulation, 'cannot cancel a canceled invoice'
|
||||
assert not self.factures_avoir.count(), 'cannot cancel twice an invoice'
|
||||
|
||||
facture_avoir = Facture.objects.get(pk=self.pk)
|
||||
facture_avoir.pk = None
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
{% 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 %}
|
||||
{% if not original.annulation %}
|
||||
{% if not original.annulation and original.factures_avoir.count == 0 %}
|
||||
<li><a href="{% url "admin:eo_facture_facture_cancel" original.id %}">Annuler</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
|
|
@ -34,6 +34,8 @@ def test_limitations(db):
|
|||
|
||||
with pytest.raises(AssertionError, match='cannot cancel a canceled invoice'):
|
||||
facture_avoir.cancel(creator)
|
||||
with pytest.raises(AssertionError, match='cannot cancel twice an invoice'):
|
||||
facture.cancel(creator)
|
||||
|
||||
|
||||
def test_facture_avoir(app):
|
||||
|
@ -54,6 +56,11 @@ def test_facture_avoir(app):
|
|||
assert 'Annuler' in [li.a.text for li in facture_0137_page.html.find_all('li')]
|
||||
facture_avoir_page = facture_0137_page.click("Annuler")
|
||||
facture_avoir_page = facture_avoir_page.follow()
|
||||
|
||||
# can't cancel invoice twice
|
||||
facture_0137_page = factures_page.click('F20190137')
|
||||
assert 'Annuler' not in [li.a.text for li in facture_0137_page.html.find_all('li')]
|
||||
|
||||
assert (
|
||||
'Facture proforma du 2019-10-09' in facture_avoir_page.html.find('div', {'class': 'breadcrumbs'}).text
|
||||
)
|
||||
|
@ -156,4 +163,3 @@ def test_facture_avoir(app):
|
|||
],
|
||||
],
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue