Commit 188f17cd by François

Modifications pour requête membre service commité et validation clic

parent d3bee25b
...@@ -671,7 +671,7 @@ class CagetteMember(models.Model): ...@@ -671,7 +671,7 @@ class CagetteMember(models.Model):
return m_list return m_list
@staticmethod @staticmethod
def search(k_type, key): def search(k_type, key, shift_id=None):
"""Search member according 3 types of key.""" """Search member according 3 types of key."""
api = OdooAPI() api = OdooAPI()
if k_type == 'id': if k_type == 'id':
...@@ -683,23 +683,38 @@ class CagetteMember(models.Model): ...@@ -683,23 +683,38 @@ class CagetteMember(models.Model):
else: else:
cond = [['name', 'ilike', str(key)]] cond = [['name', 'ilike', str(key)]]
# cond.append(['cooperative_state', '!=', 'unsubscribed']) # cond.append(['cooperative_state', '!=', 'unsubscribed'])
fields = CagetteMember.m_default_fields
res = api.search_read('res.partner', cond, CagetteMember.m_default_fields) if not shift_id is None:
CagetteMember.m_default_fields.append('tmpl_reg_line_ids')
res = api.search_read('res.partner', cond, fields)
members = [] members = []
if len(res) > 0: if len(res) > 0:
for m in res: for m in res:
try: keep_it = False
img_code = base64.b64decode(m['image_medium']) if not shift_id is None and len(shift_id) > 0:
extension = imghdr.what('', img_code) # Only member registred to shift_id will be returned
m['image_extension'] = extension cond = [['id', '=', m['tmpl_reg_line_ids'][0]]]
except Exception as e: fields = ['shift_template_id']
coop_logger.info("Img error : %s", e) shift_templ_res = api.search_read('shift.template.registration.line', cond, fields)
m['state'] = m['cooperative_state'] if (len(shift_templ_res) > 0
m['cooperative_state'] = \ and
CagetteMember.get_state_fr(m['cooperative_state']) int(shift_templ_res[0]['shift_template_id'][0]) == int(shift_id)):
# member = CagetteMember(m['id'], m['email']) keep_it = True
# m['next_shifts'] = member.get_next_shift() else:
members.append(m) keep_it = True
if keep_it is True:
try:
img_code = base64.b64decode(m['image_medium'])
extension = imghdr.what('', img_code)
m['image_extension'] = extension
except Exception as e:
coop_logger.info("Img error : %s", e)
m['state'] = m['cooperative_state']
m['cooperative_state'] = \
CagetteMember.get_state_fr(m['cooperative_state'])
# member = CagetteMember(m['id'], m['email'])
# m['next_shifts'] = member.get_next_shift()
members.append(m)
return CagetteMember.add_next_shifts_to_members(members) return CagetteMember.add_next_shifts_to_members(members)
...@@ -769,6 +784,7 @@ class CagetteMembers(models.Model): ...@@ -769,6 +784,7 @@ class CagetteMembers(models.Model):
api = OdooAPI() api = OdooAPI()
return [] return []
@staticmethod @staticmethod
def raw_search(needle): def raw_search(needle):
"""Search partner with missing elements""" """Search partner with missing elements"""
...@@ -1220,37 +1236,64 @@ class CagetteServices(models.Model): ...@@ -1220,37 +1236,64 @@ class CagetteServices(models.Model):
return result return result
@staticmethod @staticmethod
def get_committees_shift_id():
shift_id = None
try:
api = OdooAPI()
res = api.search_read('ir.config_parameter',
[['key','=', 'lacagette_membership.committees_shift_id']],
['value'])
if len(res) > 0:
try:
shift_id = int(res[0]['value'])
except:
pass
except:
pass
return shift_id
@staticmethod
def easy_validate_shift_presence(coop_id): def easy_validate_shift_presence(coop_id):
"""Add a presence point if the request is valid.""" """Add a presence point if the request is valid."""
res = {} res = {}
try: try:
committees_shift_id = CagetteServices.get_committees_shift_id()
api = OdooAPI() api = OdooAPI()
# let verify coop_id is corresponding to a ftop subscriber # let verify coop_id is corresponding to a ftop subscriber
cond = [['id', '=', coop_id]] cond = [['id', '=', coop_id]]
fields = ['shift_type'] fields = ['tmpl_reg_line_ids']
coop = api.search_read('res.partner', cond, fields) coop = api.search_read('res.partner', cond, fields)
if coop: if coop:
if coop[0]['shift_type'] == 'ftop': if len(coop[0]['tmpl_reg_line_ids']) > 0 :
evt_name = getattr(settings, 'ENTRANCE_ADD_PT_EVENT_NAME', 'Validation service comité') cond = [['id', '=', coop[0]['tmpl_reg_line_ids'][0]]]
c = [['partner_id', '=', coop_id], ['name', '=', evt_name]] fields = ['shift_template_id']
f = ['create_date'] shift_templ_res = api.search_read('shift.template.registration.line', cond, fields)
last_point_mvts = api.search_read('shift.counter.event', c, f, if (len(shift_templ_res) > 0
order ="create_date DESC", limit=1) and
ok_for_adding_pt = False shift_templ_res[0]['shift_template_id'][0] == committees_shift_id):
if len(last_point_mvts):
now = datetime.datetime.now() evt_name = getattr(settings, 'ENTRANCE_ADD_PT_EVENT_NAME', 'Validation service comité')
past = datetime.datetime. strptime(last_point_mvts[0]['create_date'], c = [['partner_id', '=', coop_id], ['name', '=', evt_name]]
'%Y-%m-%d %H:%M:%S') f = ['create_date']
if (now - past).total_seconds() >= 3600 * 24: 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 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: else:
ok_for_adding_pt = True res['error'] = "Unallowed coop"
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: else:
res['error'] = "Unallowed coop" res['error'] = "Unregistred coop"
else: else:
res['error'] = "Invalid coop id" res['error'] = "Invalid coop id"
except Exception as e: except Exception as e:
......
...@@ -786,11 +786,10 @@ $(document).ready(function() { ...@@ -786,11 +786,10 @@ $(document).ready(function() {
let search_str = sm_search_member_input.val(); let search_str = sm_search_member_input.val();
$.ajax({ $.ajax({
url: '/members/search/' + search_str, url: '/members/search/' + search_str + '/' + window.committees_shift_id,
dataType : 'json', dataType : 'json',
success: function(data) { success: function(data) {
members_search_results = []; members_search_results = [];
for (member of data.res) { for (member of data.res) {
if (member.shift_type == 'ftop') { if (member.shift_type == 'ftop') {
members_search_results.push(member); members_search_results.push(member);
......
...@@ -36,7 +36,7 @@ urlpatterns = [ ...@@ -36,7 +36,7 @@ urlpatterns = [
url(r'^verify_final_state$', views.verify_final_state), url(r'^verify_final_state$', views.verify_final_state),
url(r'^update_couchdb_barcodes$', views.update_couchdb_barcodes), url(r'^update_couchdb_barcodes$', views.update_couchdb_barcodes),
# Borne accueil # Borne accueil
url(r'^search/(.+)', views.search), url(r'^search/([^\/.]+)/?([0-9]*)', views.search),
url(r'^save_photo/([0-9]+)$', views.save_photo, name='save_photo'), url(r'^save_photo/([0-9]+)$', views.save_photo, name='save_photo'),
url(r'^services_at_time/([0-9TZ\-\: \.]+)/([0-9\-]+)$', views.services_at_time), url(r'^services_at_time/([0-9TZ\-\: \.]+)/([0-9\-]+)$', views.services_at_time),
url(r'^service_presence/$', views.record_service_presence), url(r'^service_presence/$', views.record_service_presence),
......
...@@ -41,6 +41,13 @@ def index(request): ...@@ -41,6 +41,13 @@ def index(request):
context['ftop_btn_display'] = getattr(settings, 'ENTRANCE_FTOP_BUTTON_DISPLAY', True) context['ftop_btn_display'] = getattr(settings, 'ENTRANCE_FTOP_BUTTON_DISPLAY', True)
context['extra_btns_display'] = getattr(settings, 'ENTRANCE_EXTRA_BUTTONS_DISPLAY', True) context['extra_btns_display'] = getattr(settings, 'ENTRANCE_EXTRA_BUTTONS_DISPLAY', True)
context['easy_shift_validate'] = getattr(settings, 'ENTRANCE_EASY_SHIFT_VALIDATE', False) context['easy_shift_validate'] = getattr(settings, 'ENTRANCE_EASY_SHIFT_VALIDATE', False)
if context['easy_shift_validate'] is True:
committees_shift_id = CagetteServices.get_committees_shift_id()
if committees_shift_id is None:
return HttpResponse("Le créneau des comités n'est pas configuré dans Odoo !")
else:
context['committees_shift_id'] = committees_shift_id
if 'no_picture_member_advice' in msettings: if 'no_picture_member_advice' in msettings:
if len(msettings['no_picture_member_advice']['value']) > 0: if len(msettings['no_picture_member_advice']['value']) > 0:
context['no_picture_member_advice'] = msettings['no_picture_member_advice']['value'] context['no_picture_member_advice'] = msettings['no_picture_member_advice']['value']
...@@ -227,7 +234,7 @@ def update_couchdb_barcodes(request): ...@@ -227,7 +234,7 @@ def update_couchdb_barcodes(request):
# Borne accueil # Borne accueil
def search(request, needle): def search(request, needle, shift_id):
"""Search member has been requested.""" """Search member has been requested."""
try: try:
key = int(needle) key = int(needle)
...@@ -238,8 +245,8 @@ def search(request, needle): ...@@ -238,8 +245,8 @@ def search(request, needle):
except ValueError: except ValueError:
key = needle key = needle
k_type = 'name' k_type = 'name'
res = CagetteMember.search(k_type, key) res = CagetteMember.search(k_type, key, shift_id)
return JsonResponse({'res': res}) return JsonResponse({'res': res})
......
...@@ -18,11 +18,15 @@ ...@@ -18,11 +18,15 @@
history.pushState(null, null, location.pathname) history.pushState(null, null, location.pathname)
}; };
window.late_mode = {% if LATE_MODE %}true{% else %}false{% endif %}; window.late_mode = {% if LATE_MODE %}true{% else %}false{% endif %};
{% if committees_shift_id %}
window.committees_shift_id = {{committees_shift_id}};
{% endif %}
</script> </script>
<script src="{% static "js/webcam.min.js" %}"> <script src="{% static "js/webcam.min.js" %}">
</script> </script>
<script src="{% static "js/JsBarcode.all.min.js" %}"> <script src="{% static "js/JsBarcode.all.min.js" %}">
</script> </script>
<script type="text/javascript" src="{% static 'js/notify.min.js' %}?v="></script>
<script defer src="{% static "fontawesome/js/fontawesome-all.js" %}"></script> <script defer src="{% static "fontawesome/js/fontawesome-all.js" %}"></script>
{% endblock %} {% endblock %}
......
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