Browse Source

Pb calcul today slot

12.0
Juliana 5 years ago
parent
commit
2244ff3039
  1. 2
      __manifest__.py
  2. 139
      models/vracoop_point_retrait.py
  3. 6
      static/src/js/vracoop_retrait.js
  4. 8
      views/vracoop_templates.xml

2
__manifest__.py

@ -9,7 +9,7 @@
"application": False,
"installable": True,
"depends": [
"website", "website_sale", "website_sale_delivery"
"website", "website_sale", "website_sale_delivery", "product_pack"
],
"data": [
'security/ir.model.access.csv',

139
models/vracoop_point_retrait.py

@ -78,7 +78,7 @@ class VracoopPointRetrait(models.Model):
('dimanche', 6, 0, 'dim.'),
]
for rec in self:
my_datetime = datetime.today()
today_datetime = datetime.today()
return_slot_list = []
vals = []
exclure_days_nb = rec.vracoop_retrait_time_ids.search_count([
@ -112,83 +112,53 @@ class VracoopPointRetrait(models.Model):
hour = time_available_week.strftime("%H")
minute = time_available_week.strftime("%M")
interval = int(hour)*60 + int(minute)
if week.day == my_datetime.day:
first_morning_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.first_morning_heure)
last_morning_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.last_morning_heure)
first_noon_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.first_noon_heure)
last_noon_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.last_noon_heure)
today_hour_available = my_datetime + timedelta(
hours=corresponding_line.preparation_time)
if (today_hour_available > first_morning_hour_week) and (today_hour_available < last_morning_hour_week):
dtstart_morning = today_hour_available
dtstart_noon = first_noon_hour_week
elif (today_hour_available > first_noon_hour_week) and (today_hour_available < last_noon_hour_week):
dtstart_morning = today_hour_available
dtstart_noon = today_hour_available
elif (today_hour_available > last_morning_hour_week) and (today_hour_available < first_noon_hour_week):
dtstart_morning = today_hour_available
dtstart_noon = first_noon_hour_week
else:
dtstart_morning = today_hour_available
dtstart_noon = today_hour_available
list_slot_per_day_morning = list(
rrule(
MINUTELY,
interval=interval,
byweekday=byweekday,
dtstart=dtstart_morning,
until=last_morning_hour_week))
list_slot_per_day_noon = list(
rrule(
MINUTELY,
interval=interval,
byweekday=byweekday,
dtstart=dtstart_noon,
until=last_noon_hour_week))
else:
first_morning_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.first_morning_heure)
last_morning_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.last_morning_heure)
first_noon_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.first_noon_heure)
last_noon_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.last_noon_heure)
list_slot_per_day_morning = list(
rrule(
MINUTELY,
interval=interval,
byweekday=byweekday,
dtstart=first_morning_hour_week,
until=last_morning_hour_week))
list_slot_per_day_noon = list(
rrule(
MINUTELY, interval=interval,
byweekday=byweekday,
dtstart=first_noon_hour_week,
until=last_noon_hour_week))
first_morning_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.first_morning_heure)
last_morning_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.last_morning_heure)
first_noon_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.first_noon_heure)
last_noon_hour_week = datetime(
week.year, week.month, week.day) + timedelta(
hours=corresponding_line.last_noon_heure)
list_slot_per_day_morning = list(
rrule(
MINUTELY,
interval=interval,
byweekday=byweekday,
dtstart=first_morning_hour_week,
until=last_morning_hour_week))
list_slot_per_day_noon = list(
rrule(
MINUTELY, interval=interval,
byweekday=byweekday,
dtstart=first_noon_hour_week,
until=last_noon_hour_week))
slots = []
nb_sale_slot = 0
for slot_per_day_morning in list_slot_per_day_morning:
first_slot = slot_per_day_morning.strftime("%H:%M")
slot_per_day_morning = slot_per_day_morning + timedelta(
today_hour_available = today_datetime + timedelta(
hours=corresponding_line.preparation_time)
for slot_elem in list_slot_per_day_morning:
first_slot = slot_elem.strftime("%H:%M")
slot_elem_last = slot_elem + timedelta(
hours=corresponding_line.availability_time)
last_slot = slot_per_day_morning.strftime("%H:%M")
last_slot = slot_elem_last.strftime("%H:%M")
if slot_elem.date() == today_datetime.date():
if (today_hour_available > slot_elem_last):
continue
if slot_elem_last >= last_morning_hour_week:
slot_elem_last = last_morning_hour_week
last_slot = slot_elem_last.strftime("%H:%M")
if slot_elem >= last_morning_hour_week:
continue
# 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]))
@ -199,13 +169,20 @@ class VracoopPointRetrait(models.Model):
if nb_sale_slot < rec.nb_max_retrait:
slots.append((first_slot, last_slot))
nb_sale_slot = 0
for slot_per_day_noon in list_slot_per_day_noon:
first_slot = slot_per_day_noon.strftime("%H:%M")
slot_per_day_noon = slot_per_day_noon + timedelta(
for slot_elem in list_slot_per_day_noon:
first_slot = slot_elem.strftime("%H:%M")
slot_elem_last = slot_elem + timedelta(
hours=corresponding_line.availability_time)
last_slot = slot_per_day_noon.strftime("%H:%M")
last_slot = slot_elem_last.strftime("%H:%M")
if week.date() == today_datetime.date():
if (today_hour_available > slot_elem_last):
continue
if slot_elem_last >= last_noon_hour_week:
slot_elem_last = last_noon_hour_week
last_slot = slot_elem_last.strftime("%H:%M")
if slot_elem >= last_noon_hour_week:
continue
# 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]))

6
static/src/js/vracoop_retrait.js

@ -54,7 +54,6 @@ odoo.define('vracoop_click_and_collect.vracoop_retrait', function (require) {
var _onDayClick = function(ev) {
var day_retrait = $(ev.currentTarget).val();
console.log(day_retrait);
var values = {'day_retrait': day_retrait};
dp.add(ajax.jsonRpc('/shop/update_retrait', 'call', values))
.then(_onDayUpdateAnswer);
@ -80,7 +79,6 @@ odoo.define('vracoop_click_and_collect.vracoop_retrait', function (require) {
var _onHourClick = function(ev) {
var hour_retrait = $(ev.currentTarget).val();
var values = {'hour_retrait': hour_retrait};
console.log(values);
dp.add(ajax.jsonRpc('/shop/update_retrait', 'call', values))
.then(_onHourUpdateAnswer);
};
@ -117,5 +115,9 @@ odoo.define('vracoop_click_and_collect.vracoop_retrait', function (require) {
var $carriers = $("#delivery_carrier input[name='delivery_type']");
$carriers.click(_onCarrierClick2);
if ($carriers.length > 0) {
$carriers.filter(':checked').click();
}
});

8
views/vracoop_templates.xml

@ -28,7 +28,7 @@
<t t-foreach="list_slots" t-as="slot">
<t t-if="slot_first">
<li class="nav-item carousel-item col-12 col-sm-6 col-md-4 col-lg-3 active">
<a data-toggle="tab" class="nav-link active btn btn-primary" t-attf-href='##{slot[1].strftime("%A")}#{point_retrait.id}'>
<a data-toggle="tab" class="nav-link active btn btn-primary" t-attf-href='##{slot[1].strftime("%A")}-#{slot[1].day}-#{point_retrait.id}'>
<label class=" label_radio_button" role="radio">
<input t-attf-id='#{slot[1].day}-#{slot[1].month}-#{point_retrait.id}' name="day_select d-none" type="radio" class="radio_hide" t-attf-value='#{slot[1].day}-#{slot[1].month}-#{point_retrait.id}'/>
<span class="span_radio_button">
@ -42,7 +42,7 @@
</t>
<t t-else="">
<li class="nav-item carousel-item col-12 col-sm-6 col-md-4 col-lg-3">
<a data-toggle="tab" class="nav-link btn btn-primary" t-attf-href='##{slot[1].strftime("%A")}#{point_retrait.id}'>
<a data-toggle="tab" class="nav-link btn btn-primary" t-attf-href='##{slot[1].strftime("%A")}-#{slot[1].day}-#{point_retrait.id}'>
<label class=" label_radio_button" role="radio">
<input t-attf-id='#{slot[1].day}-#{slot[1].month}-#{point_retrait.id}' name="day_select" type="radio" class="radio_hide d-none" t-attf-value='#{slot[1].day}-#{slot[1].month}-#{point_retrait.id}' />
<span class="span_radio_button">
@ -71,7 +71,7 @@
<div class="tab-content">
<t t-foreach="list_slots" t-as="slot">
<t t-if="slot_first">
<div class="container tab-pane active" t-attf-id='#{slot[1].strftime("%A")}#{point_retrait.id}'>
<div class="container tab-pane active" t-attf-id='#{slot[1].strftime("%A")}-#{slot[1].day}-#{point_retrait.id}'>
<t t-foreach="slot[3]" t-as="slot_by_day">
<label class="label_radio_button" role="radio">
<input name="hour_select" type="radio" class="radio_hide" t-attf-value="#{slot[1].day}-#{slot[1].month}-#{slot_by_day[0]}-#{point_retrait.id}" t-attf-id="#{slot_by_day_index}"/>
@ -84,7 +84,7 @@
</div>
</t>
<t t-else="">
<div class="container tab-pane fade" t-attf-id='#{slot[1].strftime("%A")}#{point_retrait.id}'>
<div class="container tab-pane fade" t-attf-id='#{slot[1].strftime("%A")}-#{slot[1].day}-#{point_retrait.id}'>
<t t-foreach="slot[3]" t-as="slot_by_day">
<label class=" label_radio_button" role="radio">
<input t-attf-id="#{slot_by_day_index}" name="hour_select" type="radio" class="radio_hide" t-attf-value="#{slot[1].day}-#{slot[1].month}-#{slot_by_day[0]}-#{point_retrait.id}"/>

Loading…
Cancel
Save