diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-04-24 13:54:06 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-04-24 13:54:06 +0700 |
| commit | d9d8b9f3afc0ad60ca1199b08ab6e2836663a0de (patch) | |
| tree | ac67e346cb6c1eb867a905f7cf2fb72e444df46d | |
| parent | a76389076431e63519835656eebdba4e4d0eda3a (diff) | |
fixing revisi renca
| -rw-r--r-- | indoteknik_api/controllers/api_v1/product.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 22 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 19 |
3 files changed, 24 insertions, 19 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py index 7d5fc580..7d6ebdb6 100644 --- a/indoteknik_api/controllers/api_v1/product.py +++ b/indoteknik_api/controllers/api_v1/product.py @@ -51,7 +51,7 @@ class Product(controller.Controller): additional_days = request.env['sale.order'].get_days_until_next_business_day(start_date) include_instant = True - if(len(products) != len(product_ids)): + if(len(products) == len(product_ids)): products_data_params = {product["id"] : product for product in product_data } all_fast_products = all( diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index c83ffd61..a7ee9db8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -496,7 +496,7 @@ class SaleOrder(models.Model): @api.depends('date_order', 'estimated_arrival_days', 'state', 'estimated_arrival_days_start') def _compute_eta_date(self): - current_date = datetime.now().date() + current_date = datetime.now() for rec in self: if rec.date_order and rec.state not in ['cancel'] and rec.estimated_arrival_days and rec.estimated_arrival_days_start: rec.eta_date = current_date + timedelta(days=rec.estimated_arrival_days) @@ -507,7 +507,19 @@ class SaleOrder(models.Model): def get_days_until_next_business_day(self,start_date=None, *args, **kwargs): - today = start_date or datetime.today().date() + 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) + offset = 0 # Counter jumlah hari yang ditambahkan holiday = self.env['hr.public.holiday'] @@ -568,13 +580,13 @@ class SaleOrder(models.Model): rec.expected_ready_to_ship = False return - current_date = datetime.now().date() + current_date = datetime.now() 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) - 1 + sum_days = max_slatime + self.get_days_until_next_business_day(current_date) if not rec.estimated_arrival_days: rec.estimated_arrival_days = sum_days @@ -597,7 +609,7 @@ 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) - 1 + sum_days = max_slatime + self.get_days_until_next_business_day(current_date) eta_minimum = current_date + timedelta(days=sum_days) if expected_date < eta_minimum: diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index f2b69b55..aa616e62 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1442,8 +1442,10 @@ class StockPicking(models.Model): def generate_eta_delivery(self): current_date = datetime.datetime.now() - prepare_days = 3 - start_date = self.driver_departure_date or self.create_date + days_start = self.sale_id.estimated_arrival_days_start or self.sale_id.estimated_arrival_days + days_end = self.sale_id.estimated_arrival_days or (self.sale_id.estimated_arrival_days + 3) + start_date = self.sale_id.create_date + datetime.timedelta(days=days_start) + end_date = self.sale_id.create_date + datetime.timedelta(days=days_end) add_day_start = 0 @@ -1456,19 +1458,10 @@ class StockPicking(models.Model): elif sale_order_delay.status == 'early': add_day_start = -abs(sale_order_delay.days_delayed) add_day_end = -abs(sale_order_delay.days_delayed) - - ead = self.sale_id.estimated_arrival_days or 0 - if not self.driver_departure_date: - ead += prepare_days - - ead_datetime = datetime.timedelta(days=ead) - fastest_eta = start_date + ead_datetime + datetime.timedelta(days=add_day_start) - if not self.driver_departure_date and fastest_eta < current_date: - fastest_eta = current_date + ead_datetime + fastest_eta = start_date +datetime.timedelta(days=add_day_start + add_day_start) - longest_days = 3 - longest_eta = fastest_eta + datetime.timedelta(days=longest_days + add_day_end) + longest_eta = end_date + datetime.timedelta(days=add_day_end) format_time = '%d %b %Y' format_time_fastest = '%d %b' if fastest_eta.year == longest_eta.year else format_time |
