forked from DGNum/gestioCOF
Enregistrement des charges et retraits K-Psul
- Ajouter une charge ou un retrait l'ajoute au formset - Envoi du panier en appuyant sur "Enter" si le focus est sur l'autocomplétion d'article puis soft reset
This commit is contained in:
parent
084b77f919
commit
a5e571de97
3 changed files with 77 additions and 7 deletions
|
@ -151,10 +151,17 @@ class KPsulCheckoutForm(forms.Form):
|
||||||
class KPsulOperationForm(forms.ModelForm):
|
class KPsulOperationForm(forms.ModelForm):
|
||||||
article = forms.ModelChoiceField(
|
article = forms.ModelChoiceField(
|
||||||
queryset=Article.objects.select_related('category').all(),
|
queryset=Article.objects.select_related('category').all(),
|
||||||
required=False)
|
required=False,
|
||||||
|
widget = forms.HiddenInput())
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Operation
|
model = Operation
|
||||||
fields = ['type', 'amount', 'is_checkout', 'article', 'article_nb']
|
fields = ['type', 'amount', 'is_checkout', 'article', 'article_nb']
|
||||||
|
widgets = {
|
||||||
|
'type': forms.HiddenInput(),
|
||||||
|
'amount': forms.HiddenInput(),
|
||||||
|
'is_checkout': forms.HiddenInput(),
|
||||||
|
'article_nb': forms.HiddenInput(),
|
||||||
|
}
|
||||||
|
|
||||||
def clean(self):
|
def clean(self):
|
||||||
super(KPsulOperationForm, self).clean()
|
super(KPsulOperationForm, self).clean()
|
||||||
|
@ -182,5 +189,6 @@ class KPsulOperationForm(forms.ModelForm):
|
||||||
KPsulOperationFormSet = modelformset_factory(
|
KPsulOperationFormSet = modelformset_factory(
|
||||||
Operation,
|
Operation,
|
||||||
form = KPsulOperationForm,
|
form = KPsulOperationForm,
|
||||||
extra = 1,
|
can_delete = True,
|
||||||
|
extra = 0,
|
||||||
min_num = 1, validate_min = True)
|
min_num = 1, validate_min = True)
|
||||||
|
|
|
@ -90,11 +90,12 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!--
|
|
||||||
<form id="operation_formset">
|
<form id="operation_formset" style="display:none">
|
||||||
{{ operation_formset.as_p }}
|
{{ operation_formset.as_p }}
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<!--
|
||||||
<button type="button" id="perform_operations">Valider</button>
|
<button type="button" id="perform_operations">Valider</button>
|
||||||
|
|
||||||
<form id="cancel_form">
|
<form id="cancel_form">
|
||||||
|
@ -102,8 +103,11 @@
|
||||||
Opé annul 2:<input type="text" name="operation">
|
Opé annul 2:<input type="text" name="operation">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<button type="button" id="cancel_operations">Annuler</button>
|
<button type="button" id="cancel_operations">Annuler</button>-->
|
||||||
-->
|
|
||||||
|
<div style="display:none;" id="operation_empty_html" data-opeindex="__prefix__">
|
||||||
|
{{ operation_formset.empty_form }}
|
||||||
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
@ -462,6 +466,10 @@ $(document).ready(function() {
|
||||||
var text = articleSelect.val();
|
var text = articleSelect.val();
|
||||||
// Comportement normal pour ces touches
|
// Comportement normal pour ces touches
|
||||||
if (normalKeys.test(e.keyCode) || e.ctrlKey) {
|
if (normalKeys.test(e.keyCode) || e.ctrlKey) {
|
||||||
|
if (text == '' && e.keyCode == 13) {
|
||||||
|
performOperations();
|
||||||
|
coolReset();
|
||||||
|
}
|
||||||
if (e.keyCode == 8)
|
if (e.keyCode == 8)
|
||||||
updateMatchedArticles(text.substring(0,text.length-1), commit=false);
|
updateMatchedArticles(text.substring(0,text.length-1), commit=false);
|
||||||
if (e.charCode == 97 && e.ctrlKey) {
|
if (e.charCode == 97 && e.ctrlKey) {
|
||||||
|
@ -577,6 +585,7 @@ $(document).ready(function() {
|
||||||
|
|
||||||
function addDeposit(amount) {
|
function addDeposit(amount) {
|
||||||
var deposit_basket_html = $(item_basket_default_html);
|
var deposit_basket_html = $(item_basket_default_html);
|
||||||
|
var index = addDepositToFormset(amount);
|
||||||
deposit_basket_html
|
deposit_basket_html
|
||||||
.find('.name').text('Charge').end()
|
.find('.name').text('Charge').end()
|
||||||
.find('.amount').text(amount);
|
.find('.amount').text(amount);
|
||||||
|
@ -585,9 +594,11 @@ $(document).ready(function() {
|
||||||
|
|
||||||
function addWithdraw(amount) {
|
function addWithdraw(amount) {
|
||||||
var withdraw_basket_html = $(item_basket_default_html);
|
var withdraw_basket_html = $(item_basket_default_html);
|
||||||
|
var amount = -amount;
|
||||||
|
var index = addWithdrawToFormset(amount);
|
||||||
withdraw_basket_html
|
withdraw_basket_html
|
||||||
.find('.name').text('Retrait').end()
|
.find('.name').text('Retrait').end()
|
||||||
.find('.amount').text(- amount);
|
.find('.amount').text(amount);
|
||||||
basket_container.prepend(withdraw_basket_html);
|
basket_container.prepend(withdraw_basket_html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -599,6 +610,56 @@ $(document).ready(function() {
|
||||||
depositButton.on('click', function() { askDeposit(); });
|
depositButton.on('click', function() { askDeposit(); });
|
||||||
withdrawButton.on('click', function() { askWithdraw(); });
|
withdrawButton.on('click', function() { askWithdraw(); });
|
||||||
|
|
||||||
|
// -----
|
||||||
|
// Add operations to form
|
||||||
|
// -----
|
||||||
|
|
||||||
|
var operation_empty_html = $('#operation_empty_html')
|
||||||
|
.removeAttr('id')
|
||||||
|
.find('label').remove().end()
|
||||||
|
.find('#id_form-__prefix__-DELETE').css('display','none').end();
|
||||||
|
$('#id_form-0-DELETE').prop('checked',true);
|
||||||
|
|
||||||
|
var formset_container = $('#operation_formset');
|
||||||
|
var mngmt_total_forms_input = $('#id_form-TOTAL_FORMS');
|
||||||
|
var mngmt_total_forms = 1;
|
||||||
|
var prefix_regex = /__prefix__/;
|
||||||
|
|
||||||
|
function add_operation_to_formset(type, amount, article='', article_nb='', is_checkout=1) {
|
||||||
|
var operation_html = operation_empty_html.clone();
|
||||||
|
var index = mngmt_total_forms;
|
||||||
|
console.log(operation_html);
|
||||||
|
|
||||||
|
operation_html
|
||||||
|
.find('#id_form-__prefix__-type').val(type).end()
|
||||||
|
.find('#id_form-__prefix__-amount').val(amount).end()
|
||||||
|
.find('#id_form-__prefix__-article').val(article).end()
|
||||||
|
.find('#id_form-__prefix__-article_nb').val(article_nb).end()
|
||||||
|
.find('#id_form-__prefix__-is_checkout').val(is_checkout);
|
||||||
|
console.log(operation_html);
|
||||||
|
|
||||||
|
mngmt_total_forms_input.val(index+1);
|
||||||
|
mngmt_total_forms++;
|
||||||
|
|
||||||
|
operation_html.find(':input').each(function() {
|
||||||
|
var name = $(this).attr('name').replace(prefix_regex, index);
|
||||||
|
var id = 'id_' + name;
|
||||||
|
$(this).attr({'name': name, 'id': id});
|
||||||
|
});
|
||||||
|
console.log(operation_html);
|
||||||
|
formset_container.append(operation_html);
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
function addDepositToFormset(amount, is_checkout=1) {
|
||||||
|
return add_operation_to_formset('deposit', amount, '', '', is_checkout);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addWithdrawToFormset(amount, is_checkout=1) {
|
||||||
|
return add_operation_to_formset('withdraw', amount, '', '', is_checkout);
|
||||||
|
}
|
||||||
|
|
||||||
// -----
|
// -----
|
||||||
// History
|
// History
|
||||||
// -----
|
// -----
|
||||||
|
|
|
@ -408,6 +408,7 @@ def kpsul(request):
|
||||||
data['checkout_form'] = KPsulCheckoutForm()
|
data['checkout_form'] = KPsulCheckoutForm()
|
||||||
operation_formset = KPsulOperationFormSet(queryset=Operation.objects.none())
|
operation_formset = KPsulOperationFormSet(queryset=Operation.objects.none())
|
||||||
data['operation_formset'] = operation_formset
|
data['operation_formset'] = operation_formset
|
||||||
|
print(operation_formset.empty_form)
|
||||||
return render(request, 'kfet/kpsul.html', data)
|
return render(request, 'kfet/kpsul.html', data)
|
||||||
|
|
||||||
@permission_required('kfet.is_team')
|
@permission_required('kfet.is_team')
|
||||||
|
|
Loading…
Reference in a new issue