diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-05-16 08:46:53 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-05-16 08:46:53 +0700 |
| commit | 847a025e889ae9dcfe9ff97c913c9310695fc2c5 (patch) | |
| tree | ea25f7c80b040a65de6dc11c0adb6ace697266b8 | |
| parent | b2dcb44e3ff9a49c5b0b56cb7d722281790f1195 (diff) | |
handle is 3 pm
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 3 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 45 |
2 files changed, 18 insertions, 30 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index ecd37cda..e97a7ff8 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -50,7 +50,8 @@ class Product(controller.Controller): jakarta = pytz.timezone("Asia/Jakarta") start_date = datetime.now(jakarta) - additional_days = request.env['sale.order'].get_days_until_next_business_day(start_date) + offset, is3pm = request.env['sale.order'].get_days_until_next_business_day(start_date) + additional_days = offset include_instant = True diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 795bfa0b..1d318c46 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -2,7 +2,7 @@ from re import search from odoo import fields, models, api, _ from odoo.exceptions import UserError, ValidationError -from datetime import datetime, timedelta, timezone +from datetime import datetime, timedelta, timezone, time import logging, random, string, requests, math, json, re, qrcode, base64 from io import BytesIO from collections import defaultdict @@ -541,28 +541,6 @@ class SaleOrder(models.Model): rec.eta_date_start = False - 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 - - # Pastikan start_date pakai timezone Jakarta - if start_date.tzinfo is None: - start_date = jakarta.localize(start_date) - - # Jika sudah lewat jam 15:00, mulai dari hari berikutnya - 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") now = datetime.now(jakarta) @@ -577,9 +555,11 @@ class SaleOrder(models.Model): batas_waktu = datetime.strptime("15:00", "%H:%M").time() current_day = start_date.date() offset = 0 + is3pm = False # Step 1: Lewat jam 15 → Tambah 1 hari if start_date.time() > batas_waktu: + is3pm = True offset += 1 # Step 2: Hitung hari libur selama offset itu @@ -613,8 +593,8 @@ class SaleOrder(models.Model): else: break - final_offset = (current_day - start_date.date()).days - return final_offset + offset = (current_day - start_date.date()).days + return offset, is3pm @@ -666,13 +646,19 @@ 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) + + offset , is3pm = self.get_days_until_next_business_day(current_date) + sum_days = max_slatime + offset sum_days -= 1 if not rec.estimated_arrival_days: rec.estimated_arrival_days = sum_days eta_date = current_date + timedelta(days=sum_days) + if is3pm: + eta_date = datetime.combine(eta_date, time(10, 0)) # jam 10:00 + eta_date = jakarta.localize(eta_date).astimezone(timezone.utc) # ubah ke UTC + + eta_date = eta_date.astimezone(timezone.utc).replace(tzinfo=None) rec.commitment_date = eta_date rec.expected_ready_to_ship = eta_date @@ -692,8 +678,9 @@ 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) + + offset , is3pm = self.get_days_until_next_business_day(current_date) + sum_days = max_slatime + offset sum_days -= 1 eta_minimum = current_date + timedelta(days=sum_days) |
