Commit 8c96561a by Damien Moulard

update history logic

parents 2bafd38f c1ebf735
Pipeline #1540 passed with stage
in 1 minute 32 seconds
......@@ -125,7 +125,7 @@ RECEPTION_PB = "Ici, vous pouvez signaler toute anomalie lors d'une réception,
Merci d'indiquer un maximum d'informations, le nom du produit et son code barre. \
Dans le cas de produits déteriorés, merci d'envoyer une photo avec votre téléphone à [Adresse_email]"
AMNISTIE_DATE= "2021-11-24"
AMNISTIE_DATE= "2021-11-24 00:00:00"
# display or not column "Autres" in reception process
DISPLAY_COL_AUTRES = False
......
......@@ -13,7 +13,8 @@ class CagetteMembersSpace(models.Model):
def get_shifts_history(self, partner_id, limit, offset, date_from):
""" Get partner shifts history """
res = {}
res = []
paginated_res = []
today = str(datetime.date.today())
try:
......@@ -27,21 +28,70 @@ class CagetteMembersSpace(models.Model):
['state', '!=', 'replaced'],
['state', '!=', 'replacing'],
]
f = ['create_date', 'shift_id', 'name', 'state', 'is_late', 'is_makeup']
f = ['create_date', 'date_begin', 'shift_id', 'name', 'state', 'is_late', 'is_makeup']
marshal_none_error = 'cannot marshal None unless allow_none is enabled'
try:
res = self.o_api.search_read('shift.registration', cond, f, limit=limit, offset=offset,
order='date_begin DESC')
res = self.o_api.search_read('shift.registration', cond, f, order='date_begin DESC')
except Exception as e:
if not (marshal_none_error in str(e)):
res['error'] = repr(e)
coop_logger.error(res['error'] + ' : %s', str(payment_id))
print(str(e))
coop_logger.error(repr(e) + ' : %s', str(partner_id))
else:
res = []
# Get committees shifts
committees_shifts_name = getattr(settings, 'ENTRANCE_ADD_PT_EVENT_NAME', 'Validation service comité')
cond = [
['partner_id', '=', partner_id],
['name', '=', committees_shifts_name]
]
f = ['create_date']
try:
res_committees_shifts = self.o_api.search_read('shift.counter.event', cond, f, order='create_date DESC')
for committee_shift in res_committees_shifts:
item = {
"create_date": committee_shift["create_date"],
"date_begin": committee_shift["create_date"],
"shift_id": False,
"name": "Services des comités",
"state": "done",
"is_late": False,
"is_makeup": False,
}
res.append(item)
except Exception as e:
if not (marshal_none_error in str(e)):
print(str(e))
coop_logger.error(repr(e) + ' : %s', str(partner_id))
else:
res = res + []
# Add amnesty line
is_amnesty = getattr(settings, 'AMNISTIE_DATE', 'false')
company_code = getattr(settings, 'COMPANY_CODE', '')
if is_amnesty and company_code == "lacagette":
amnesty={}
amnesty['is_amnesty'] = True
amnesty['create_date'] = is_amnesty
amnesty['date_begin'] = is_amnesty
amnesty['shift_name'] = 'Amnistie'
amnesty['state'] = ''
res.append(amnesty)
# ordering
res.sort(key = lambda x: datetime.datetime.strptime(x['date_begin'], '%Y-%m-%d %H:%M:%S'), reverse=True)
# Paginate
end_index = offset + limit
paginated_res = res[offset:end_index]
except Exception as e:
print(str(e))
return res
return paginated_res
\ No newline at end of file
......@@ -84,12 +84,9 @@ table.dataTable.display tbody tr.row_partner_absent {
background-color: #ff847b;
}
table.dataTable.display tbody tr.row_partner_amnistie {
background-color: black;
background-color: rgb(78, 78, 78);
color: white;
}
table.dataTable.display tbody tr.row_partner_ok td,
table.dataTable.display tbody tr.row_partner_late td,
table.dataTable.display tbody tr.row_partner_absent td {
border-bottom: 1px solid rgb(100, 99, 99);
border-top: 1px solid rgb(100, 99, 99);
table.dataTable.display tbody tr td {
border-top: 1px solid rgb(119, 119, 119);
}
\ No newline at end of file
......@@ -48,6 +48,23 @@ function prepare_server_data(data) {
res = [];
for (history_item of data) {
if (history_item.is_amnesty !== undefined) {
let shift_datetime = new Date(history_item.date_begin);
let str_shift_datetime = `${("0" + shift_datetime.getDate()).slice(-2)}/${("0" + (shift_datetime.getMonth() + 1)).slice(-2)}/${shift_datetime.getFullYear()}`
history_item.shift_name = `${history_item.shift_name} du ${str_shift_datetime}`
} else {
history_item.shift_name = (history_item.shift_id === false) ? '' : history_item.shift_id[1];
if (history_item.name === "Services des comités") {
let shift_datetime = new Date(history_item.date_begin);
let str_shift_datetime = `${("0" + shift_datetime.getDate()).slice(-2)}/${("0" + (shift_datetime.getMonth() + 1)).slice(-2)}/${shift_datetime.getFullYear()}`
str_shift_datetime = str_shift_datetime + " " + shift_datetime.toLocaleTimeString("fr-fr", time_options);
history_item.shift_name = `Services des comités ${str_shift_datetime}`
}
}
history_item.details = '';
if (history_item.state === 'excused' || history_item.state === 'absent') {
history_item.details = "Absent";
......@@ -58,7 +75,6 @@ function prepare_server_data(data) {
} else if (history_item.state === 'cancel') {
history_item.details = "Annulé";
}
if (history_item.is_amnesty == undefined) history_item.shift_name = (history_item.shift_id === false) ? '' : history_item.shift_id[1];
}
return data;
......@@ -104,7 +120,7 @@ function init_history() {
$(row).addClass('row_partner_late');
} else if (cell.text() === "Absent") {
$(row).addClass('row_partner_absent');
} else if (cell.text() === "Amnistie") {
} else if (cell.text().includes("Amnistie")) {
$(row).addClass('row_partner_amnistie');
}
}
......
......@@ -221,15 +221,5 @@ def get_shifts_history(request):
offset = int(request.GET.get('offset'))
date_from = getattr(settings, 'START_DATE_FOR_SHIFTS_HISTORY', '2018-01-01')
res["data"] = m.get_shifts_history(partner_id, limit, offset, date_from)
is_amnesty = getattr(settings, 'AMNISTIE_DATE', 'false')
company_code = getattr(settings, 'COMPANY_CODE', '')
if is_amnesty and company_code == "lacagette":
amnesty={}
amnesty['is_amnesty'] = True
amnesty['create_date'] = is_amnesty
amnesty['shift_name'] = 'Amnistie'
amnesty['state'] = ''
res["data"].append(amnesty)
return JsonResponse(res)
\ No newline at end of file
......@@ -311,7 +311,7 @@
Message shown to people when they connect to the Member Space
- AMNISTIE_DATE = "2021-11-24"
- AMNISTIE_DATE = "2021-11-24 00:00:00"
In members_space history display a special activity about amnistie
### Reception
......
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