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):
return m_list
@staticmethod
def search(k_type, key):
def search(k_type, key, shift_id=None):
"""Search member according 3 types of key."""
api = OdooAPI()
if k_type == 'id':
......@@ -683,23 +683,38 @@ class CagetteMember(models.Model):
else:
cond = [['name', 'ilike', str(key)]]
# cond.append(['cooperative_state', '!=', 'unsubscribed'])
res = api.search_read('res.partner', cond, CagetteMember.m_default_fields)
fields = 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 = []
if len(res) > 0:
for m in res:
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)
keep_it = False
if not shift_id is None and len(shift_id) > 0:
# Only member registred to shift_id will be returned
cond = [['id', '=', m['tmpl_reg_line_ids'][0]]]
fields = ['shift_template_id']
shift_templ_res = api.search_read('shift.template.registration.line', cond, fields)
if (len(shift_templ_res) > 0
and
int(shift_templ_res[0]['shift_template_id'][0]) == int(shift_id)):
keep_it = True
else:
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)
......@@ -769,6 +784,7 @@ class CagetteMembers(models.Model):
api = OdooAPI()
return []
@staticmethod
def raw_search(needle):
"""Search partner with missing elements"""
......@@ -1220,37 +1236,64 @@ class CagetteServices(models.Model):
return result
@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):
"""Add a presence point if the request is valid."""
res = {}
try:
committees_shift_id = CagetteServices.get_committees_shift_id()
api = OdooAPI()
# let verify coop_id is corresponding to a ftop subscriber
cond = [['id', '=', coop_id]]
fields = ['shift_type']
fields = ['tmpl_reg_line_ids']
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:
if len(coop[0]['tmpl_reg_line_ids']) > 0 :
cond = [['id', '=', coop[0]['tmpl_reg_line_ids'][0]]]
fields = ['shift_template_id']
shift_templ_res = api.search_read('shift.template.registration.line', cond, fields)
if (len(shift_templ_res) > 0
and
shift_templ_res[0]['shift_template_id'][0] == committees_shift_id):
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:
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"
res['error'] = "Unallowed coop"
else:
res['error'] = "Unallowed coop"
res['error'] = "Unregistred coop"
else:
res['error'] = "Invalid coop id"
except Exception as e:
......
......@@ -786,11 +786,10 @@ $(document).ready(function() {
let search_str = sm_search_member_input.val();
$.ajax({
url: '/members/search/' + search_str,
url: '/members/search/' + search_str + '/' + window.committees_shift_id,
dataType : 'json',
success: function(data) {
members_search_results = [];
for (member of data.res) {
if (member.shift_type == 'ftop') {
members_search_results.push(member);
......
......@@ -36,7 +36,7 @@ urlpatterns = [
url(r'^verify_final_state$', views.verify_final_state),
url(r'^update_couchdb_barcodes$', views.update_couchdb_barcodes),
# 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'^services_at_time/([0-9TZ\-\: \.]+)/([0-9\-]+)$', views.services_at_time),
url(r'^service_presence/$', views.record_service_presence),
......
......@@ -41,6 +41,13 @@ def index(request):
context['ftop_btn_display'] = getattr(settings, 'ENTRANCE_FTOP_BUTTON_DISPLAY', True)
context['extra_btns_display'] = getattr(settings, 'ENTRANCE_EXTRA_BUTTONS_DISPLAY', True)
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 len(msettings['no_picture_member_advice']['value']) > 0:
context['no_picture_member_advice'] = msettings['no_picture_member_advice']['value']
......@@ -227,7 +234,7 @@ def update_couchdb_barcodes(request):
# Borne accueil
def search(request, needle):
def search(request, needle, shift_id):
"""Search member has been requested."""
try:
key = int(needle)
......@@ -238,8 +245,8 @@ def search(request, needle):
except ValueError:
key = needle
k_type = 'name'
res = CagetteMember.search(k_type, key)
res = CagetteMember.search(k_type, key, shift_id)
return JsonResponse({'res': res})
......
......@@ -18,11 +18,15 @@
history.pushState(null, null, location.pathname)
};
window.late_mode = {% if LATE_MODE %}true{% else %}false{% endif %};
{% if committees_shift_id %}
window.committees_shift_id = {{committees_shift_id}};
{% endif %}
</script>
<script src="{% static "js/webcam.min.js" %}">
</script>
<script src="{% static "js/JsBarcode.all.min.js" %}">
</script>
<script type="text/javascript" src="{% static 'js/notify.min.js' %}?v="></script>
<script defer src="{% static "fontawesome/js/fontawesome-all.js" %}"></script>
{% 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