contract: add a link to bill recurrence from change form (#71664)
This commit is contained in:
parent
74810b68d5
commit
cc48705afc
|
@ -308,6 +308,40 @@ class Contrat(models.Model):
|
||||||
self.factures.update(numero_d_echeance=None)
|
self.factures.update(numero_d_echeance=None)
|
||||||
return super().save(*args, **kwargs)
|
return super().save(*args, **kwargs)
|
||||||
|
|
||||||
|
def has_echeance_to_bill(self):
|
||||||
|
if self.periodicite is None:
|
||||||
|
return False
|
||||||
|
|
||||||
|
until = (now() + relativedelta(months=6)).date()
|
||||||
|
|
||||||
|
facture_par_numero_d_echeance = {
|
||||||
|
facture.numero_d_echeance: facture
|
||||||
|
for facture in self.factures.all()
|
||||||
|
if facture.echeance and not facture.proforma
|
||||||
|
}
|
||||||
|
for i, _, __ in self.periodicite_echeances(until=until):
|
||||||
|
if i not in facture_par_numero_d_echeance:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def next_echeance_to_bill(self):
|
||||||
|
until = (now() + relativedelta(months=6)).date()
|
||||||
|
echeances = []
|
||||||
|
|
||||||
|
facture_par_numero_d_echeance = {
|
||||||
|
facture.numero_d_echeance: facture
|
||||||
|
for facture in self.factures.all()
|
||||||
|
if facture.echeance and not facture.proforma
|
||||||
|
}
|
||||||
|
for i, periode_debut, periode_fin in self.periodicite_echeances(until=until):
|
||||||
|
if i in facture_par_numero_d_echeance:
|
||||||
|
continue
|
||||||
|
echeances.append((periode_debut, periode_fin, i))
|
||||||
|
echeances.sort()
|
||||||
|
if len(echeances) > 0:
|
||||||
|
return echeances[0][2]
|
||||||
|
return -1
|
||||||
|
|
||||||
def __str__(self): # pylint: disable=invalid-str-returned
|
def __str__(self): # pylint: disable=invalid-str-returned
|
||||||
return self.intitule
|
return self.intitule
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,14 @@
|
||||||
<li><a href="{% url "admin:eo_facture_contrat_duplicate" original.id %}">Dupliquer</a></li>
|
<li><a href="{% url "admin:eo_facture_contrat_duplicate" original.id %}">Dupliquer</a></li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li><a href="{% url "admin:eo_facture_facture_changelist" %}?contrat={{ original.id }}">Factures</a></li>
|
<li><a href="{% url "admin:eo_facture_facture_changelist" %}?contrat={{ original.id }}">Factures</a></li>
|
||||||
|
{% if original.has_echeance_to_bill %}
|
||||||
|
<li><a href="javascript:document.getElementById('facturer_echeance_form').submit();">Facturer</a></li>
|
||||||
|
<form id="facturer_echeance_form" method="post" action="{% url "admin:eo_facture_contrat_facturer_echeance" original.id %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="echeance" value="{{ original.next_echeance_to_bill }}"/>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
{% if not original.periodicite %}
|
{% if not original.periodicite %}
|
||||||
<li><a href="{% url "admin:eo_facture_facture_add" %}?contrat={{ original.id }}&client={{ original.client.id }}&taux_tva={{ original.tva }}">Ajouter une facture</a></li>
|
<li><a href="{% url "admin:eo_facture_facture_add" %}?contrat={{ original.id }}&client={{ original.client.id }}&taux_tva={{ original.tva }}">Ajouter une facture</a></li>
|
||||||
<li><a href="{% url "admin:eo_facture_facture_add_simple" %}?contrat={{ original.id }}">Ajouter une facture comme pourcentage du total</a></li>
|
<li><a href="{% url "admin:eo_facture_facture_add_simple" %}?contrat={{ original.id }}">Ajouter une facture comme pourcentage du total</a></li>
|
||||||
|
|
|
@ -44,8 +44,8 @@ class TestLoggedIn:
|
||||||
response.form['periodicite'] = 'annuelle'
|
response.form['periodicite'] = 'annuelle'
|
||||||
response.form['periodicite_debut'] = '2018-12-01'
|
response.form['periodicite_debut'] = '2018-12-01'
|
||||||
response = response.form.submit('_continue').follow()
|
response = response.form.submit('_continue').follow()
|
||||||
response.form['periodicite_debut'] = '2018-12-02'
|
response.forms["contrat_form"]['periodicite_debut'] = '2018-12-02'
|
||||||
response = response.form.submit('_continue').follow()
|
response = response.forms["contrat_form"].submit('_continue').follow()
|
||||||
|
|
||||||
# Créer la facture de première échéance
|
# Créer la facture de première échéance
|
||||||
response = app.get('/')
|
response = app.get('/')
|
||||||
|
|
Loading…
Reference in New Issue