8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-22 19:33:11 +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") banque = cleaned_data.get("banque")
if not paiement: if not paiement:
raise forms.ValidationError("Le moyen de paiement est obligatoire.") 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.") raise forms.ValidationError("Le numéro de chèque et la banque sont obligatoires.")
return cleaned_data return cleaned_data
@ -112,11 +112,12 @@ class DelArticleForm(ModelForm):
class PaiementForm(ModelForm): class PaiementForm(ModelForm):
class Meta: class Meta:
model = Paiement model = Paiement
fields = ['moyen'] fields = ['moyen', 'type_']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(PaiementForm, self).__init__(*args, **kwargs) super(PaiementForm, self).__init__(*args, **kwargs)
self.fields['moyen'].label = 'Moyen de paiement à ajouter' self.fields['moyen'].label = 'Moyen de paiement à ajouter'
self.fields['type_'].label = 'Type de paiement à ajouter'
class DelPaiementForm(ModelForm): class DelPaiementForm(ModelForm):
paiements = forms.ModelMultipleChoiceField(queryset=Paiement.objects.all(), label="Moyens de paiement actuels", widget=forms.CheckboxSelectMultiple) 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): class Paiement(models.Model):
PRETTY_NAME = "Moyens de paiement" PRETTY_NAME = "Moyens de paiement"
PAYMENT_TYPES = (
('check', 'Chèque'),
(None, 'Autre'),
)
moyen = models.CharField(max_length=255) moyen = models.CharField(max_length=255)
type_ = models.ChoiceField(choices=PAYMENT_TYPES)
def __str__(self): def __str__(self):
return self.moyen 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> <h3>Nouvelle facture</h3>
{% bootstrap_form factureform %} {% bootstrap_form factureform %}
{{ venteform.management_form }} {{ venteform.management_form }}
<!-- TODO: FIXME to include data-type="check" for right option in id_cheque select -->
<h3>Articles de la facture</h3> <h3>Articles de la facture</h3>
<div id="form_set"> <div id="form_set">
{% for form in venteform.forms %} {% 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"> <script type="text/javascript">
// id from database from checks var prices = {};
var CHECK_ID = 2;
var prices = {}
{% for article in articlelist %} {% for article in articlelist %}
prices[{{ article.id|escapejs }}] = {{ article.prix }}; prices[{{ article.id|escapejs }}] = {{ article.prix }};
{% endfor %} {% endfor %}
@ -111,17 +109,15 @@ with this program; if not, write to the Free Software Foundation, Inc.,
} }
function set_cheque_info_visibility(){ function set_cheque_info_visibility(){
// May break in various ways... var paiement = document.getElementById("id_paiement");
// Requires CHECK_ID to be the right one var visible = paiement.value != '' &&
// and fields to hide to be 2nd and 3rd elements with class form-group paiement.children[paiement.value].dataset['type'] == 'check';
var visible = document.getElementById("id_paiement").value == CHECK_ID;
var display = 'none'; var display = 'none';
if (visible) { if (visible) {
display = 'block'; display = 'block';
} }
var elements = document.getElementsByClassName('form-group'); document.getElementById("id_cheque").parentNode.style.display = display;
elements[1].style.display = display; document.getElementById("id_banque").parentNode.style.display = display;
elements[2].style.display = display;
} }
// Add events manager when DOM is fully loaded // Add events manager when DOM is fully loaded