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 | |
| parent | e8938477ca3f87a55b0e4ca313481fe8d7e8fef4 (diff) | |
handle bugs additional time when checkout > 15.00
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 10 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 49 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 8 |
3 files changed, 39 insertions, 28 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 7d6ebdb6..bd969f67 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -2,6 +2,7 @@ from .. import controller from odoo import http from odoo.http import request, Response from datetime import datetime, timedelta +import pytz import ast import logging import math @@ -46,8 +47,9 @@ class Product(controller.Controller): ('product_id', 'in', product_ids), ('is_winner', '=', True) ]) - - start_date = datetime.today().date() + jakarta = pytz.timezone("Asia/Jakarta") + start_date = datetime.now(jakarta) + print(start_date.strftime('%H:%M')) additional_days = request.env['sale.order'].get_days_until_next_business_day(start_date) include_instant = True @@ -64,7 +66,7 @@ class Product(controller.Controller): 'include_instant': include_instant, 'sla_duration': 1, 'sla_additional_days': additional_days, - 'sla_total' : int(1) + int(additional_days), + 'sla_total' : int(additional_days), 'sla_unit': 'Hari' }) @@ -160,7 +162,7 @@ class Product(controller.Controller): else: if qty_available > 0: qty = qty_available - sla_date = f'{slatime} Hari' + sla_date = f'1 Hari' elif qty_vendor > 0: qty = total_excell sla_date = f'{slatime} Hari' 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, |
