|
|
@ -65,7 +65,8 @@ class VracoopPointRetrait(models.Model): |
|
|
|
string="Configuration des horaires") |
|
|
|
nb_max_retrait = fields.Integer( |
|
|
|
"Nombre de retrait max par tranche horaire") |
|
|
|
nb_day_available = fields.Integer("Nombre de jours pour commande") |
|
|
|
nb_day_available = fields.Integer( |
|
|
|
"Nombre de jours pour commande", default=7) |
|
|
|
|
|
|
|
@api.multi |
|
|
|
def slot_calculate(self): |
|
|
@ -100,12 +101,16 @@ class VracoopPointRetrait(models.Model): |
|
|
|
('active_day', '=', False)]) |
|
|
|
count_day = rec.nb_day_available + exclure_days_nb |
|
|
|
|
|
|
|
# Liste des jours où je peux récupérer la commande |
|
|
|
# en fonction nombre de jour dispo sur la fiche du point retrait |
|
|
|
list_week = list(rrule( |
|
|
|
DAILY, |
|
|
|
count=count_day, |
|
|
|
dtstart=datetime.today())) |
|
|
|
|
|
|
|
for week in list_week: |
|
|
|
# On exclut les jours où la journée |
|
|
|
# du point de retrait n'est pas actif |
|
|
|
exclure_the_day = rec.vracoop_retrait_time_ids.search([ |
|
|
|
('vracoop_point_retrait_id', '=', rec.id), |
|
|
|
('active_day', '=', False), |
|
|
@ -113,13 +118,18 @@ class VracoopPointRetrait(models.Model): |
|
|
|
if exclure_the_day: |
|
|
|
pass |
|
|
|
else: |
|
|
|
# Récupération de la ligne du jour correpsondant |
|
|
|
corresponding_line = rec.vracoop_retrait_time_ids.search([ |
|
|
|
('vracoop_point_retrait_id', '=', rec.id), |
|
|
|
('name', '=', week.strftime("%w"))]) |
|
|
|
|
|
|
|
# Récupération du nom du jour et du Short name du jour |
|
|
|
for week_day in LIST_WEEK_DAY: |
|
|
|
if week_day[2] == int(week.strftime("%w")): |
|
|
|
byweekday = week_day[1] |
|
|
|
day_short_name = week_day[3] |
|
|
|
|
|
|
|
# Calcul de l'heure à laquelle la commande est disponible |
|
|
|
time_available_week = datetime( |
|
|
|
week.year, week.month, week.day) + timedelta( |
|
|
|
hours=corresponding_line.availability_time) |
|
|
@ -140,6 +150,9 @@ class VracoopPointRetrait(models.Model): |
|
|
|
week.year, week.month, week.day) + timedelta( |
|
|
|
hours=corresponding_line.last_noon_heure) |
|
|
|
|
|
|
|
# Calcul des Slots (matin et après-midi) par jour en |
|
|
|
# fonction de l'intervalle (correspondant au temps de mis |
|
|
|
# à disposition) et des dates de début et de fin de retrait |
|
|
|
list_slot_per_day_morning = list( |
|
|
|
rrule( |
|
|
|
MINUTELY, |
|
|
@ -156,64 +169,104 @@ class VracoopPointRetrait(models.Model): |
|
|
|
slots = [] |
|
|
|
nb_sale_slot = 0 |
|
|
|
|
|
|
|
# Heure disponible pour un retrait |
|
|
|
# en fonction du temps de préparation |
|
|
|
today_hour_available = today_datetime + timedelta( |
|
|
|
hours=corresponding_line.preparation_time) |
|
|
|
|
|
|
|
# Boucle pour les créneaux du matin |
|
|
|
for slot_elem in list_slot_per_day_morning: |
|
|
|
# Conversion du 1er Slot en HH:MM |
|
|
|
first_slot = slot_elem.strftime("%H:%M") |
|
|
|
|
|
|
|
# Calcul du dernier slot |
|
|
|
# en fonction du temps de mis à dsiposition |
|
|
|
slot_elem_last = slot_elem + timedelta( |
|
|
|
hours=corresponding_line.availability_time) |
|
|
|
# Conversion du Dernier Slot en HH:MM |
|
|
|
last_slot = slot_elem_last.strftime("%H:%M") |
|
|
|
|
|
|
|
if slot_elem >= last_morning_hour_week: |
|
|
|
continue |
|
|
|
|
|
|
|
# Si le jour est égal à la date du jour |
|
|
|
if slot_elem.date() == today_datetime.date(): |
|
|
|
if (slot_elem_last > last_morning_hour_week): |
|
|
|
if (today_hour_available > last_morning_hour_week): |
|
|
|
continue |
|
|
|
if (today_hour_available > slot_elem_last): |
|
|
|
continue |
|
|
|
if (today_hour_available > slot_elem): |
|
|
|
slot_elem_first = today_hour_available + timedelta( |
|
|
|
hours=1.0) |
|
|
|
first_slot = slot_elem_first.strftime("%H:00") |
|
|
|
if first_slot == last_slot: |
|
|
|
continue |
|
|
|
if slot_elem_last >= last_morning_hour_week: |
|
|
|
slot_elem_last = last_morning_hour_week |
|
|
|
last_slot = slot_elem_last.strftime("%H:%M") |
|
|
|
# Check number of maximum withdrawal not reached |
|
|
|
first_slot_hour = first_slot.split(":") |
|
|
|
first_slot_float = float( |
|
|
|
'%s.%s' % (first_slot_hour[0], first_slot_hour[1])) |
|
|
|
nb_sale_slot = self.env['sale.order'].search_count( |
|
|
|
[('vracoop_point_retrait_id', '=', rec.id), |
|
|
|
('day_retrait', '=', week.date()), |
|
|
|
('hour_retrait', '=', first_slot_float)]) |
|
|
|
if nb_sale_slot < rec.nb_max_retrait: |
|
|
|
|
|
|
|
# Vérification si |
|
|
|
# Nombre max de retrait défini a été atteint |
|
|
|
# Pas de controle si La valeur définie est 0 |
|
|
|
if rec.nb_max_retrait > 0: |
|
|
|
first_slot_hour = first_slot.split(":") |
|
|
|
first_slot_float = float( |
|
|
|
'%s.%s' % (first_slot_hour[0], first_slot_hour[1])) |
|
|
|
nb_sale_slot = self.env['sale.order'].search_count( |
|
|
|
[('vracoop_point_retrait_id', '=', rec.id), |
|
|
|
('day_retrait', '=', week.date()), |
|
|
|
('hour_retrait', '=', first_slot_float)]) |
|
|
|
if nb_sale_slot < rec.nb_max_retrait: |
|
|
|
slots.append((first_slot, last_slot)) |
|
|
|
else: |
|
|
|
slots.append((first_slot, last_slot)) |
|
|
|
|
|
|
|
# Boucle pour les créneaux de l'après-midi |
|
|
|
for slot_elem in list_slot_per_day_noon: |
|
|
|
# Conversion du 1er Slot en HH:MM |
|
|
|
first_slot = slot_elem.strftime("%H:%M") |
|
|
|
|
|
|
|
# Calcul du dernier slot |
|
|
|
# en fonction du temps de mis à dsiposition |
|
|
|
slot_elem_last = slot_elem + timedelta( |
|
|
|
hours=corresponding_line.availability_time) |
|
|
|
# Conversion du Dernier Slot en HH:MM |
|
|
|
last_slot = slot_elem_last.strftime("%H:%M") |
|
|
|
if slot_elem >= last_noon_hour_week: |
|
|
|
continue |
|
|
|
|
|
|
|
# Si le jour est égal à la date du jour |
|
|
|
if slot_elem.date() == today_datetime.date(): |
|
|
|
if (slot_elem_last > last_noon_hour_week): |
|
|
|
if (today_hour_available > last_noon_hour_week): |
|
|
|
continue |
|
|
|
if (today_hour_available > slot_elem_last): |
|
|
|
continue |
|
|
|
|
|
|
|
if (today_hour_available > slot_elem): |
|
|
|
slot_elem_first = today_hour_available + timedelta( |
|
|
|
hours=1.0) |
|
|
|
first_slot = slot_elem_first.strftime("%H:00") |
|
|
|
if first_slot == last_slot: |
|
|
|
continue |
|
|
|
if slot_elem_last >= last_noon_hour_week: |
|
|
|
slot_elem_last = last_noon_hour_week |
|
|
|
last_slot = slot_elem_last.strftime("%H:%M") |
|
|
|
|
|
|
|
# Check number of maximum withdrawal not reached |
|
|
|
first_slot_hour = first_slot.split(":") |
|
|
|
first_slot_float = float( |
|
|
|
'%s.%s' % (first_slot_hour[0], first_slot_hour[1])) |
|
|
|
nb_sale_slot = self.env['sale.order'].search_count( |
|
|
|
[('vracoop_point_retrait_id', '=', rec.id), |
|
|
|
('day_retrait', '=', week.date()), |
|
|
|
('hour_retrait', '=', first_slot_float)]) |
|
|
|
if nb_sale_slot < rec.nb_max_retrait: |
|
|
|
# Vérification si |
|
|
|
# Nombre max de retrait défini a été atteint |
|
|
|
# Pas de controle si La valeur définie est 0 |
|
|
|
if rec.nb_max_retrait > 0: |
|
|
|
first_slot_hour = first_slot.split(":") |
|
|
|
first_slot_float = float( |
|
|
|
'%s.%s' % (first_slot_hour[0], first_slot_hour[1])) |
|
|
|
nb_sale_slot = self.env['sale.order'].search_count( |
|
|
|
[('vracoop_point_retrait_id', '=', rec.id), |
|
|
|
('day_retrait', '=', week.date()), |
|
|
|
('hour_retrait', '=', first_slot_float)]) |
|
|
|
if nb_sale_slot < rec.nb_max_retrait: |
|
|
|
slots.append((first_slot, last_slot)) |
|
|
|
else: |
|
|
|
slots.append((first_slot, last_slot)) |
|
|
|
|
|
|
|
return_slot_list = slots |
|
|
|