8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-05 01:16:27 +00:00

Rework facture management to avoid hardcoded check database id in JS.

This commit is contained in:
David Sinquin 2017-07-18 23:57:57 +02:00
parent 8515b2b051
commit bbe687c29b
3 changed files with 15 additions and 13 deletions

View file

@ -46,7 +46,7 @@ class NewFactureForm(ModelForm):
banque = cleaned_data.get("banque")
if not paiement:
raise forms.ValidationError("Le moyen de paiement est obligatoire.")
elif paiement.moyen.lower()=="chèque" or paiement.moyen.lower()=="cheque" and not (cheque and banque):
elif paiement.type_ == "check" and not (cheque and banque):
raise forms.ValidationError("Le numéro de chèque et la banque sont obligatoires.")
return cleaned_data
@ -112,11 +112,12 @@ class DelArticleForm(ModelForm):
class PaiementForm(ModelForm):
class Meta:
model = Paiement
fields = ['moyen']
fields = ['moyen', 'type_']
def __init__(self, *args, **kwargs):
super(PaiementForm, self).__init__(*args, **kwargs)
self.fields['moyen'].label = 'Moyen de paiement à ajouter'
self.fields['type_'].label = 'Type de paiement à ajouter'
class DelPaiementForm(ModelForm):
paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple)

View file

@ -130,8 +130,13 @@ class Banque(models.Model):
class Paiement(models.Model):
PRETTY_NAME = "Moyens de paiement"
PAYMENT_TYPES = (
('check', 'Chèque'),
(None, 'Autre'),
)
moyen = models.CharField(max_length=255)
type_ = models.ChoiceField(choices=PAYMENT_TYPES)
def __str__(self):
return self.moyen

View file

@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<h3>Nouvelle facture</h3>
{% bootstrap_form factureform %}
{{ venteform.management_form }}
<!-- TODO: FIXME to include data-type="check" for right option in id_cheque select -->
<h3>Articles de la facture</h3>
<div id="form_set">
{% for form in venteform.forms %}
@ -57,10 +58,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<script type="text/javascript">
// id from database from checks
var CHECK_ID = 2;
var prices = {}
var prices = {};
{% for article in articlelist %}
prices[{{ article.id|escapejs }}] = {{ article.prix }};
{% endfor %}
@ -111,17 +109,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
}
function set_cheque_info_visibility(){
// May break in various ways...
// Requires CHECK_ID to be the right one
// and fields to hide to be 2nd and 3rd elements with class form-group
var visible = document.getElementById("id_paiement").value == CHECK_ID;
var paiement = document.getElementById("id_paiement");
var visible = paiement.value != '' &&
paiement.children[paiement.value].dataset['type'] == 'check';
var display = 'none';
if (visible) {
display = 'block';
}
var elements = document.getElementsByClassName('form-group');
elements[1].style.display = display;
elements[2].style.display = display;
document.getElementById("id_cheque").parentNode.style.display = display;
document.getElementById("id_banque").parentNode.style.display = display;
}
// Add events manager when DOM is fully loaded