Commit 5790b181 by Yvon Kerdoncuff

Merge branch '4709' into 'dev_cooperatic'

#4394 : allow comitee members to add as many points they want

See merge request !220
parents 644261a5 17058eca
Pipeline #2730 passed with stage
in 1 minute 30 seconds
...@@ -146,3 +146,6 @@ AMNISTIE_DATE= "2021-11-24 00:00:00" ...@@ -146,3 +146,6 @@ AMNISTIE_DATE= "2021-11-24 00:00:00"
# BDM Admin # BDM Admin
BDM_SHOW_FTOP_BUTTON = True BDM_SHOW_FTOP_BUTTON = True
# Entree
MINIMUM_SECONDS_BETWEEN_TWO_COMITEE_VALIDATION = 0
\ No newline at end of file
...@@ -870,27 +870,36 @@ class CagetteServices(models.Model): ...@@ -870,27 +870,36 @@ class CagetteServices(models.Model):
if (len(shift_templ_res) > 0 if (len(shift_templ_res) > 0
and and
shift_templ_res[0]['shift_template_id'][0] == committees_shift_id): shift_templ_res[0]['shift_template_id'][0] == committees_shift_id):
ok_for_adding_pt = False
mininum_seconds_interval = getattr(settings, 'MINIMUM_SECONDS_BETWEEN_TWO_COMITEE_VALIDATION', 3600 * 24)
evt_name = getattr(settings, 'ENTRANCE_ADD_PT_EVENT_NAME', 'Validation service comité') evt_name = getattr(settings, 'ENTRANCE_ADD_PT_EVENT_NAME', 'Validation service comité')
if mininum_seconds_interval > 0:
# A constraint has been set to prevent from adding more than 1 point during a time period
# Let's find out when was the last time a "special point" has been addes
c = [['partner_id', '=', coop_id], ['name', '=', evt_name]] c = [['partner_id', '=', coop_id], ['name', '=', evt_name]]
f = ['create_date'] f = ['create_date']
last_point_mvts = api.search_read('shift.counter.event', c, f, last_point_mvts = api.search_read('shift.counter.event', c, f,
order ="create_date DESC", limit=1) order ="create_date DESC", limit=1)
ok_for_adding_pt = False
if len(last_point_mvts): if len(last_point_mvts):
now = datetime.datetime.now() now = datetime.datetime.now()
past = datetime.datetime. strptime(last_point_mvts[0]['create_date'], past = datetime.datetime. strptime(last_point_mvts[0]['create_date'],
'%Y-%m-%d %H:%M:%S') '%Y-%m-%d %H:%M:%S')
if (now - past).total_seconds() >= 3600 * 24: if (now - past).total_seconds() >= mininum_seconds_interval:
ok_for_adding_pt = True
else:
ok_for_adding_pt = True ok_for_adding_pt = True
else: else:
# mininum_seconds_interval is 0 : Point can we added without any condition
ok_for_adding_pt = True ok_for_adding_pt = True
if ok_for_adding_pt is True: if ok_for_adding_pt is True:
res['evt_id'] = CagetteMember(coop_id).add_pts('ftop', 1, evt_name) res['evt_id'] = CagetteMember(coop_id).add_pts('ftop', 1, evt_name)
else: else:
res['error'] = "One point has been added less then 24 hours ago" res['error'] = "Un point a déjà été ajouté trop récemment."
else: else:
res['error'] = "Unallowed coop" res['error'] = "Vous n'avez pas le droit d'ajouter un point."
else: else:
res['error'] = "Unregistred coop" res['error'] = "Unregistred coop"
else: else:
......
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