summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-06-10 10:36:45 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-06-10 10:36:45 +0700
commit05dafe1ab837cac8992d1dc6c012a26bce88c15c (patch)
treef29b5333dad43722a8bffdafec94606f2bfac68d
parent5c76eb43188de9a09380dc43dcc19120b6ebfc84 (diff)
push code apit
-rwxr-xr-xindoteknik_custom/models/sale_order.py49
1 files changed, 33 insertions, 16 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index eab4f2f3..baa8207f 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -2091,11 +2091,22 @@ class SaleOrder(models.Model):
# @api.depends('commitment_date')
def _compute_ready_to_ship_status_detail(self):
+ def is_empty(val):
+ """Helper untuk cek data kosong yang umum di Odoo."""
+ return val is None or val == "" or val == [] or val == {}
+
for order in self:
- eta = order.commitment_date if order.commitment_date else None
+ order.ready_to_ship_status_detail = 'On Track' # Default value
+
+ # Skip if no commitment date
+ if is_empty(order.commitment_date):
+ continue
+
+ eta = order.commitment_date
match_lines = self.env['purchase.order.sales.match'].search([
('sale_id', '=', order.id)
])
+
if match_lines:
for match in match_lines:
po = match.purchase_order_id
@@ -2104,25 +2115,31 @@ class SaleOrder(models.Model):
('order_id', '=', po.id),
('product_id', '=', product.id)
], limit=1)
+
+ if is_empty(po_line):
+ continue
+
stock_move = self.env['stock.move'].search([
('purchase_line_id', '=', po_line.id)
], limit=1)
+
+ if is_empty(stock_move) or is_empty(stock_move.picking_id):
+ continue
+
picking_in = stock_move.picking_id
- result_date = picking_in.date_done if picking_in else None
- if result_date:
- status = "Delay"
- if result_date and eta and result_date < eta:
- status = "Early"
- result_date_str = result_date.strftime('%m/%d/%Y')
- eta_str = eta.strftime('%m/%d/%Y')
- order.ready_to_ship_status_detail = f"Expected: {eta_str} | Realtime: {result_date_str} | {status}"
- elif not eta:
- # If eta is missing or False, treat as 'On Track' or you may choose different logic
- order.ready_to_ship_status_detail = "On Track"
- else:
- order.ready_to_ship_status_detail = "On Track"
- else:
- order.ready_to_ship_status_detail = 'On Track'
+ result_date = picking_in.date_done
+
+ if is_empty(result_date):
+ continue
+
+ try:
+ if result_date < eta:
+ order.ready_to_ship_status_detail = f"Early (Actual: {result_date.strftime('%m/%d/%Y')})"
+ else:
+ order.ready_to_ship_status_detail = f"Delay (Actual: {result_date.strftime('%m/%d/%Y')})"
+ except Exception as e:
+ _logger.error(f"Error computing ready to ship status: {str(e)}")
+ continue
def write(self, vals):