diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-04-30 13:55:26 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-04-30 13:55:26 +0700 |
| commit | c77d250353dbed0ba1ec5cd8abd940ba95a011fc (patch) | |
| tree | 176ae9334bab1369e9c21e6b6230d59ab90f13b3 | |
| parent | 509eb9406e6c48caf3e6366c3d8ac60643b71546 (diff) | |
handle 15am dan holidays
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 4 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 45 |
2 files changed, 31 insertions, 18 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 0c26f064..9566ed05 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -49,7 +49,9 @@ class Product(controller.Controller): ]) jakarta = pytz.timezone("Asia/Jakarta") start_date = datetime.now(jakarta) - print(start_date.strftime('%H:%M')) + additional_days_after_3pm = request.env['sale.order'].handling_order_after_3pm(start_date) + start_date += timedelta(days=additional_days_after_3pm) + additional_days = request.env['sale.order'].get_days_until_next_business_day(start_date) include_instant = True diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 91905037..25c1b3a8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -541,12 +541,13 @@ class SaleOrder(models.Model): rec.eta_date_start = False - def get_days_until_next_business_day(self, start_date=None, *args, **kwargs): + def handling_order_after_3pm(self, start_date=None, *args, **kwargs): jakarta = pytz.timezone("Asia/Jakarta") current = datetime.now(jakarta) offset = 0 - + + # Gunakan current time kalau start_date tidak diberikan if start_date is None: start_date = current @@ -559,28 +560,31 @@ class SaleOrder(models.Model): batas_waktu = datetime.strptime("15:00", "%H:%M").time() if start_date.time() > batas_waktu: offset += 1 + + return offset + + def get_days_until_next_business_day(self, start_date=None, *args, **kwargs): + jakarta = pytz.timezone("Asia/Jakarta") + current = datetime.now(jakarta) + + offset = 0 + i = 0 current_day = start_date.date() holiday = self.env['hr.public.holiday'] - + while True: - # Tambah satu hari, cek apakah hari kerja - current_day += timedelta(days=1) - + # # Tambah satu hari, cek apakah hari kerja + current_day += timedelta(days=i) + i = 1 + # Lewati weekend is_weekend = current_day.weekday() >= 5 - - if is_weekend: - offset += 1 - continue - - # Lewati hari libur is_holiday = holiday.search([("start_date", "=", current_day)]) - - if is_holiday: + if is_weekend or is_holiday: offset += 1 continue - + break return offset @@ -633,8 +637,11 @@ class SaleOrder(models.Model): max_slatime = 1 # Default SLA jika tidak ada slatime = self.calculate_sla_by_vendor(rec.order_line) max_slatime = max(max_slatime, slatime['slatime']) + + days_after_3pm = self.handling_order_after_3pm(current_date) + date_after_3pm = current_date + timedelta(days=days_after_3pm) - sum_days = max_slatime + self.get_days_until_next_business_day(current_date) + sum_days = max_slatime + self.get_days_until_next_business_day(date_after_3pm) if not rec.estimated_arrival_days: rec.estimated_arrival_days = sum_days @@ -658,7 +665,11 @@ class SaleOrder(models.Model): max_slatime = 1 # Default SLA jika tidak ada slatime = self.calculate_sla_by_vendor(rec.order_line) max_slatime = max(max_slatime, slatime['slatime']) - sum_days = max_slatime + self.get_days_until_next_business_day(current_date) + + days_after_3pm = self.handling_order_after_3pm(current_date) + date_after_3pm = current_date + timedelta(days=days_after_3pm) + + sum_days = max_slatime + self.get_days_until_next_business_day(date_after_3pm) eta_minimum = current_date + timedelta(days=sum_days) if expected_date < eta_minimum.date(): |
