Commit d0157c9c by François

Allow Special FTOP to easy validate shift (and eslint auto fix)

parent bfbd616f
...@@ -1176,6 +1176,44 @@ class CagetteServices(models.Model): ...@@ -1176,6 +1176,44 @@ class CagetteServices(models.Model):
result['service_found'] = False result['service_found'] = False
return result return result
@staticmethod
def easy_validate_shift_presence(coop_id):
"""Add a presence point if the request is valid."""
res = {}
try:
api = OdooAPI()
# let verify coop_id is corresponding to a ftop subscriber
cond = [['id', '=', coop_id]]
fields = ['shift_type']
coop = api.search_read('res.partner', cond, fields)
if coop:
if coop[0]['shift_type'] == 'ftop':
evt_name = getattr(settings, 'ENTRANCE_ADD_PT_EVENT_NAME', 'Validation service comité')
c = [['partner_id', '=', coop_id], ['name', '=', evt_name]]
f = ['create_date']
last_point_mvts = api.search_read('shift.counter.event', c, f,
order ="create_date DESC", limit=1)
ok_for_adding_pt = False
if len(last_point_mvts):
now = datetime.datetime.now()
past = datetime.datetime. strptime(last_point_mvts[0]['create_date'],
'%Y-%m-%d %H:%M:%S')
if (now - past).total_seconds() >= 3600 * 24:
ok_for_adding_pt = True
else:
ok_for_adding_pt = True
if ok_for_adding_pt is True:
res['evt_id'] = CagetteMember(coop_id).add_pts('ftop', 1, evt_name)
else:
res['error'] = "One point has been added less then 24 hours ago"
else:
res['error'] = "Unallowed coop"
else:
res['error'] = "Invalid coop id"
except Exception as e:
coop_logger.error("easy_validate_shift_presence : %s %s", str(coop_id), str(e))
return res
class CagetteUser(models.Model): class CagetteUser(models.Model):
@staticmethod @staticmethod
......
...@@ -24,6 +24,8 @@ var current_displayed_member = null, ...@@ -24,6 +24,8 @@ var current_displayed_member = null,
rattrapage_ou_volant = null, rattrapage_ou_volant = null,
timeout_counter = null; timeout_counter = null;
var search_button = $('.btn--primary.search'); var search_button = $('.btn--primary.search');
var sm_search_member_button = $('#sm_search_member_button'),
sm_search_member_input = $('#sm_search_member_input');
var loading2 = $('.loading2'); var loading2 = $('.loading2');
var search_field = $('input[name="search_string"]'); var search_field = $('input[name="search_string"]');
var shift_title = $('#current_shift_title'); var shift_title = $('#current_shift_title');
...@@ -163,7 +165,7 @@ function canSearch() { ...@@ -163,7 +165,7 @@ function canSearch() {
function search_member(force_search = false) { function search_member(force_search = false) {
chars = []; // to prevent false "as barcode-reader" input chars = []; // to prevent false "as barcode-reader" input
operator = null operator = null;
if (canSearch() || force_search) { if (canSearch() || force_search) {
html_elts.member_slide.hide(); html_elts.member_slide.hide();
...@@ -281,11 +283,15 @@ function fill_service_entry(s) { ...@@ -281,11 +283,15 @@ function fill_service_entry(s) {
rattrapage_wanted.show(); rattrapage_wanted.show();
} }
function clean_service_entry() { function clean_search_for_easy_validate_zone() {
$('.search_member_results_area').hide(); $('.search_member_results_area').hide();
$('.search_member_results').empty(); $('.search_member_results').empty();
$('#sm_search_member_input').val(''); sm_search_member_input.val('');
operator = null operator = null;
}
function clean_service_entry() {
clean_search_for_easy_validate_zone();
rattrapage_wanted.hide(); rattrapage_wanted.hide();
shift_title.text(''); shift_title.text('');
shift_members.html(''); shift_members.html('');
...@@ -677,30 +683,30 @@ function ask_for_easy_shift_validation() { ...@@ -677,30 +683,30 @@ function ask_for_easy_shift_validation() {
//alert("operator = " + JSON.stringify(operator)) //alert("operator = " + JSON.stringify(operator))
msg = "<p>Je suis bien " + operator.name + "<br/> et <br/>je valide mon service 'Comité' </p>"; msg = "<p>Je suis bien " + operator.name + "<br/> et <br/>je valide mon service 'Comité' </p>";
openModal(msg, function() { openModal(msg, function() {
try { try {
post_form( post_form(
'/members/easy_validate_shift_presence', '/members/easy_validate_shift_presence',
{ {
coop_id: operator.id, coop_id: operator.id
},
}, function(err, result) {
function(err, result) { if (!err) {
console.log(result); alert("1 point volant vient d'être ajouté.");
if (!err) { clean_search_for_easy_validate_zone();
if (typeof(result.msg) != "undefined") { closeModal();
alert(result.msg); } else {
} else if (result.action === null) { if (typeof (err.responseJSON) != "undefined"
console.log('ok') && typeof (err.responseJSON.error) != "undefined") {
} alert(err.responseJSON.error);
closeModal(); } else {
} else { console.log(err);
console.log(err) }
}
}
);
} catch (e) {
console.log(e);
} }
}
);
} catch (e) {
console.log(e);
}
}, 'Confirmer'); }, 'Confirmer');
} }
// Display the members from the search result (copied from stock_movements) // Display the members from the search result (copied from stock_movements)
...@@ -723,13 +729,11 @@ function display_possible_members() { ...@@ -723,13 +729,11 @@ function display_possible_members() {
+ '</button>'; + '</button>';
$('.search_member_results').append(member_button); $('.search_member_results').append(member_button);
// Set action on click on a member button // Set action on click on a member button
$('.btn_member').on('click', function() { $('.btn_member').on('click', function() {
for (member of members_search_results) { for (member of members_search_results) {
if (member.id == $(this).attr('member_id')) { if (member.id == $(this).attr('member_id')) {
operator = member; operator = member;
// Enable validation button when operator is selected // Enable validation button when operator is selected
ask_for_easy_shift_validation(); ask_for_easy_shift_validation();
break; break;
...@@ -784,37 +788,43 @@ $(document).ready(function() { ...@@ -784,37 +788,43 @@ $(document).ready(function() {
}); });
$('#sm_search_member_form').submit(function() { $('#sm_search_member_form').submit(function() {
let search_str = $('#sm_search_member_input').val(); if (is_time_to('search_member', 1000)) {
$.ajax({ sm_search_member_button.empty().append(`<i class="fas fa-spinner fa-spin"></i>`);
url: '/members/search/' + search_str, let search_str = sm_search_member_input.val();
dataType : 'json',
success: function(data) { $.ajax({
members_search_results = []; url: '/members/search/' + search_str,
dataType : 'json',
for (member of data.res) { success: function(data) {
console.log(member) members_search_results = [];
if (member.shift_type == 'ftop') {
members_search_results.push(member); for (member of data.res) {
if (member.shift_type == 'ftop') {
members_search_results.push(member);
}
} }
display_possible_members();
},
error: function(data) {
err = {
msg: "erreur serveur lors de la recherche de membres",
ctx: 'easy_validate.search_members'
};
report_JS_error(err, 'members');
$.notify("Erreur lors de la recherche de membre, il faut ré-essayer plus tard...", {
globalPosition:"top right",
className: "error"
});
},
complete: function() {
sm_search_member_button.empty().append(`Recherche`);
} }
});
}
});
display_possible_members();
},
error: function(data) {
err = {
msg: "erreur serveur lors de la recherche de membres",
ctx: 'easy_validate.search_members'
};
report_JS_error(err, 'members');
$.notify("Erreur lors de la recherche de membre, il faut ré-essayer plus tard...", {
globalPosition:"top right",
className: "error"
});
}
});
})
}); });
Webcam.on('live', function() { Webcam.on('live', function() {
......
...@@ -286,7 +286,20 @@ def record_service_presence(request): ...@@ -286,7 +286,20 @@ def record_service_presence(request):
return JsonResponse({'res': res}) return JsonResponse({'res': res})
def easy_validate_shift_presence(request): def easy_validate_shift_presence(request):
return JsonResponse({}) """Add a presence point if the request is valid."""
res = {}
try:
coop_id = int(request.POST.get("coop_id", "nan"))
res = CagetteServices.easy_validate_shift_presence(coop_id)
except Exception as e:
res['error'] = str(e)
if 'error' in res:
if res['error'] == "One point has been added less then 24 hours ago":
# TODO : use translation (all project wide)
res['error'] = "Vous ne pouvez pas valider plus d'un service par 24h"
return JsonResponse(res, status=500)
else:
return JsonResponse(res, safe=False)
def record_absences(request): def record_absences(request):
return JsonResponse({'res': CagetteServices.record_absences()}) return JsonResponse({'res': CagetteServices.record_absences()})
......
...@@ -230,8 +230,11 @@ ...@@ -230,8 +230,11 @@
- ENTRANCE_EXTRA_BUTTONS_DISPLAY = False (no button is shown above shift coop. list) (True if not set) - ENTRANCE_EXTRA_BUTTONS_DISPLAY = False (no button is shown above shift coop. list) (True if not set)
- ENTRANCE_EASY_SHIFT_VALIDATE = False (default value) When set to True allow coop to identify and have 1 point (only if FTOP) - ENTRANCE_EASY_SHIFT_VALIDATE = False (default value)
When set to True allow coop to identify and have 1 point (only if FTOP)
- ENTRANCE_ADD_PT_EVENT_NAME = 'Add 1 point name throught easy validate' (default : 'Validation service comité'')
### Member space ### Member space
- EM_URL = '' - EM_URL = ''
......
...@@ -59,10 +59,9 @@ function post_form(url, data, callback) { ...@@ -59,10 +59,9 @@ function post_form(url, data, callback) {
$.post(ajax_params) $.post(ajax_params)
.done(function(rData) { .done(function(rData) {
callback(null, rData); callback(null, rData);
}) })
.fail(function(err) { .fail(function(err) {
console.log(err); callback(err, {});
}); });
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment