diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-04-26 08:39:32 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-04-26 08:39:32 +0700 |
| commit | 914705630f61f2e02f15ee24a479191e945a0f22 (patch) | |
| tree | 86af6a17b401ceb849ab445628fb22bfc8a119c2 /indoteknik_custom/models | |
| parent | e8938477ca3f87a55b0e4ca313481fe8d7e8fef4 (diff) | |
handle bugs additional time when checkout > 15.00
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 49 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 8 |
2 files changed, 33 insertions, 24 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 3117a330..1e40d15e 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -6,6 +6,7 @@ from datetime import datetime, timedelta import logging, random, string, requests, math, json, re, qrcode, base64 from io import BytesIO from collections import defaultdict +import pytz _logger = logging.getLogger(__name__) @@ -540,34 +541,42 @@ class SaleOrder(models.Model): rec.eta_date_start = False - def get_days_until_next_business_day(self,start_date=None, *args, **kwargs): - now = start_date or datetime.now() - - # Jika hanya diberikan tanggal (tanpa jam), asumsikan jam 00:00 - if isinstance(now, datetime): - order_datetime = now - else: - order_datetime = datetime.combine(now, datetime.min.time()) - - today = order_datetime.date() - - if order_datetime.time() > datetime.strptime("15:00", "%H:%M").time(): - today += timedelta(days=1) + def get_days_until_next_business_day(self, start_date=None, *args, **kwargs): + jakarta = pytz.timezone("Asia/Jakarta") + current = datetime.now(jakarta) - offset = 0 # Counter jumlah hari yang ditambahkan + 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 + + current_day = start_date.date() holiday = self.env['hr.public.holiday'] - while True : - today += timedelta(days=1) + while True: + # Tambah satu hari, cek apakah hari kerja + current_day += timedelta(days=1) offset += 1 - - if today.weekday() >= 5: + + # Lewati weekend + if current_day.weekday() >= 5: continue - is_holiday = holiday.search([("start_date", "=", today)]) + # Lewati hari libur + is_holiday = holiday.search([("start_date", "=", current_day)]) if is_holiday: continue - + break return offset diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 36129f00..38a1173c 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -562,6 +562,10 @@ class StockPicking(models.Model): }) payload = { + "origin_coordinate" :{ + "latitude": -6.3031123, + "longitude" : 106.7794934999 + }, "reference_id " : self.sale_id.name, "shipper_contact_name": self.carrier_id.pic_name or '', "shipper_contact_phone": self.carrier_id.pic_phone or '', @@ -585,10 +589,6 @@ class StockPicking(models.Model): # Cek jika pengiriman instant atau same_day if self.sale_id.delivery_service_type and ("instant" in self.sale_id.delivery_service_type or "same_day" in self.sale_id.delivery_service_type): payload.update({ - "origin_coordinate" :{ - "latitude": -6.3031123, - "longitude" : 106.7794934999 - }, "destination_coordinate" : { "latitude": self.real_shipping_id.latitude, "longitude": self.real_shipping_id.longtitude, |
