Exemple #1
0
    def is_in_delivery_window(self, date_time):
        """
        Checks if provided date_time is in a delivery window for actual partner

        :param date_time: Datetime object
        :return: Boolean
        """
        self.ensure_one()
        if self.delivery_time_preference == "workdays":
            if date_time.weekday() > 4:
                return False
            return True
        windows = self.get_delivery_windows(date_time.weekday()).get(self.id)
        if windows:
            for w in windows:
                start_time = w.get_time_window_start_time()
                end_time = w.get_time_window_end_time()
                if self.tz:
                    utc_start = tz_utils.tz_to_utc_time(self.tz, start_time)
                    utc_end = tz_utils.tz_to_utc_time(self.tz, end_time)
                else:
                    utc_start = start_time
                    utc_end = end_time
                if utc_start <= date_time.time() < utc_end:
                    return True
        return False
 def _expected_date(self):
     """Postpone expected_date to next cut-off"""
     expected_date = super()._expected_date()
     cutoff = self.order_id.get_cutoff_time()
     if not cutoff:
         return expected_date
     cutoff_tz = cutoff.get("tz")
     cutoff_time = time(hour=cutoff.get("hour"), minute=cutoff.get("minute"))
     if cutoff_tz:
         utc_cutoff_time = tz_utils.tz_to_utc_time(
             cutoff_tz, cutoff_time, base_date=expected_date
         )
     else:
         utc_cutoff_time = cutoff_time
     # FIXME: consider warehouse TZ
     # See https://github.com/OCA/sale-workflow/pull/1104#discussion_r406156787
     if expected_date.time() <= utc_cutoff_time:
         return expected_date
     return expected_date + timedelta(days=1)