diff options
| author | trisusilo48 <tri.susilo@altama.co.id> | 2025-03-10 04:36:11 +0700 |
|---|---|---|
| committer | trisusilo48 <tri.susilo@altama.co.id> | 2025-03-10 04:36:11 +0700 |
| commit | c80a48e26b972b203229e128209bb8da89d5da57 (patch) | |
| tree | eb9608e919351a7f0b43d9cbcc471f7c03912ce2 | |
| parent | 5d7bf2741610d1aecb20b7d28d76e800941025ee (diff) | |
bugs fix rts date
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 64 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 36 |
2 files changed, 74 insertions, 26 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 4f85027a..e8bba662 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -450,7 +450,7 @@ class SaleOrder(models.Model): @api.depends('date_order', 'estimated_arrival_days', 'state', 'estimated_arrival_days_start') def _compute_eta_date(self): for rec in self: - if rec.date_order and rec.state not in ['cancel'] and rec.estimated_arrival_days: + if rec.date_order and rec.state not in ['cancel'] and rec.estimated_arrival_days and rec.estimated_arrival_days_start: rec.eta_date = rec.date_order + timedelta(days=rec.estimated_arrival_days) rec.eta_date_start = rec.date_order + timedelta(days=rec.estimated_arrival_days_start) else: @@ -477,26 +477,74 @@ class SaleOrder(models.Model): break return offset + + # def calculate_sla_by_vendor(self, products): + # slatime = 15 + # for line in products: + # product_sla = self.env['product.sla'].search([('product_variant_id', '=', line.product_id.id)], limit=1) + # slatime = int(product_sla.sla) if product_sla and product_sla.sla and product_sla.sla != 'Indent' and "hari" in product_sla.sla.lower() else 15 + + # return { + # 'slatime' : slatime + # } + + def calculate_sla_by_vendor(self, products): + product_ids = products.mapped('product_id.id') # Kumpulkan semua ID produk + include_instant = True # Default True, tetapi bisa menjadi False + + # Cek apakah SEMUA produk memiliki qty_free_bandengan >= qty_needed + all_fast_products = all(product.product_id.qty_free_bandengan >= product.product_uom_qty for product in products) + if all_fast_products: + return {'slatime': 1, 'include_instant': include_instant} + + + # Cari semua vendor pemenang untuk produk yang diberikan + vendors = self.env['purchase.pricelist'].search([ + ('product_id', 'in', product_ids), + ('is_winner', '=', True) + ]) + + max_slatime = 1 + + for vendor in vendors: + vendor_sla = self.env['vendor.sla'].search([('id_vendor', '=', vendor.vendor_id.id)], limit=1) + slatime = 15 + if vendor_sla: + if vendor_sla.unit == 'hari': + vendor_duration = vendor_sla.duration * 24 * 60 + else : + vendor_duration = vendor_sla.duration * 60 + include_instant = True + + estimation_sla = (1 * 24 * 60) + vendor_duration + estimation_sla_days = estimation_sla / (24 * 60) + slatime = math.ceil(estimation_sla_days) + + max_slatime = max(max_slatime, slatime) + + return {'slatime': max_slatime, 'include_instant': include_instant} @api.depends("order_line.product_id") def _compute_etrts_date(self): #Function to calculate Estimated Ready To Ship Date for rec in self: max_slatime = 1 # Default SLA jika tidak ada - for line in rec.order_line: - product_sla = self.env['product.sla'].search([('product_variant_id', '=', line.product_id.id)], limit=1) - # if(product_sla == False): - # continue - slatime = int(product_sla.sla) if product_sla and product_sla.sla and product_sla.sla != 'Indent' and "hari" in product_sla.sla.lower() else 15 - max_slatime = max(max_slatime, slatime) + slatime = self.calculate_sla_by_vendor(rec.order_line) + max_slatime = max(max_slatime, slatime['slatime']) if rec.date_order: - eta_date = rec.date_order + timedelta(days=self.get_days_until_next_business_day(rec.date_order)) + timedelta(days=max_slatime) + sum_days = max_slatime + self.get_days_until_next_business_day(rec.date_order) - 1 + if not rec.estimated_arrival_days: + rec.estimated_arrival_days = sum_days + + eta_date = rec.date_order + timedelta(days=sum_days) rec.estimated_ready_ship_date = eta_date rec.commitment_date = eta_date # Jika expected_ready_to_ship kosong, set nilai default if not rec.expected_ready_to_ship: rec.expected_ready_to_ship = eta_date + + @api.onchange('expected_ready_to_ship') #Hangle Onchange form Expected Ready to Ship def _onchange_expected_ready_ship_date(self): for rec in self: diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 217f234e..b8bdcd94 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -190,26 +190,26 @@ class StockPicking(models.Model): self.env.cr.execute(query) - @api.depends('estimated_ready_ship_date', 'state') - def _callculate_sequance(self): - for record in self: - try : - if record.estimated_ready_ship_date and record.state not in ('cancel', 'done'): - rts = record.estimated_ready_ship_date - waktu.now() - rts_days = rts.days - rts_hours = divmod(rts.seconds, 3600) + # @api.depends('estimated_ready_ship_date', 'state') + # def _callculate_sequance(self): + # for record in self: + # try : + # if record.estimated_ready_ship_date and record.state not in ('cancel', 'done'): + # rts = record.estimated_ready_ship_date - waktu.now() + # rts_days = rts.days + # rts_hours = divmod(rts.seconds, 3600) - estimated_by_erts = rts.total_seconds() / 3600 + # estimated_by_erts = rts.total_seconds() / 3600 - record.countdown_ready_to_ship = f"{rts_days} days, {rts_hours} hours" - record.countdown_hours = estimated_by_erts - else: - record.countdown_hours = 999999999999 - record.countdown_ready_to_ship = False - except Exception as e : - _logger.error(f"Error calculating sequance {record.id}: {str(e)}") - print(str(e)) - return { 'error': str(e) } + # record.countdown_ready_to_ship = f"{rts_days} days, {rts_hours} hours" + # record.countdown_hours = estimated_by_erts + # else: + # record.countdown_hours = 999999999999 + # record.countdown_ready_to_ship = False + # except Exception as e : + # _logger.error(f"Error calculating sequance {record.id}: {str(e)}") + # print(str(e)) + # return { 'error': str(e) } # @api.depends('estimated_ready_ship_date', 'state') |
