From fe458043667bb7f1cde757659fefe0174252002d Mon Sep 17 00:00:00 2001 From: it-fixcomart Date: Mon, 2 Jun 2025 01:09:39 +0700 Subject: estimasi barang sampai fix> --- indoteknik_custom/models/sale_order.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index f1280b37..aa1b4b49 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -1057,16 +1057,23 @@ class SaleOrder(models.Model): rec.compute_fullfillment = True - @api.depends('date_order', 'estimated_arrival_days', 'state', 'estimated_arrival_days_start') + @api.depends('expected_ready_to_ship', 'shipping_option_id.etd', 'state') def _compute_eta_date(self): - 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) - rec.eta_date_start = current_date + timedelta(days=rec.estimated_arrival_days_start) + for rec in self: + if rec.expected_ready_to_ship and rec.shipping_option_id and rec.shipping_option_id.etd and rec.state not in ['cancel']: + etd_text = rec.shipping_option_id.etd + match = re.match(r"(\d+)\s*-\s*(\d+)", etd_text) + if match: + start_days = int(match.group(1)) + end_days = int(match.group(2)) + rec.eta_date_start = rec.expected_ready_to_ship + timedelta(days=start_days) + rec.eta_date = rec.expected_ready_to_ship + timedelta(days=end_days) + else: + rec.eta_date_start = False + rec.eta_date = False else: - rec.eta_date = False rec.eta_date_start = False + rec.eta_date = False def get_days_until_next_business_day(self, start_date=None, *args, **kwargs): -- cgit v1.2.3