summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2025-03-19 10:04:31 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2025-03-19 10:04:31 +0700
commitfc5defa647bcdd317dc2d4069432c2dcc1141344 (patch)
treeb60748119a9ff488843d7d1286f8a5e60806dc66
parente4d86ee7cb2fac5c09876b1aeefda04f27ebedd0 (diff)
change mthode validation expected date
-rwxr-xr-xindoteknik_custom/models/sale_order.py87
1 files changed, 45 insertions, 42 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 7ccc551b..e2755eba 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -190,10 +190,10 @@ class SaleOrder(models.Model):
('PNR', 'Pareto Non Repeating'),
('NP', 'Non Pareto')
])
- estimated_ready_ship_date = fields.Datetime(
- string='ET Ready to Ship compute',
- compute='_compute_etrts_date'
- )
+ # estimated_ready_ship_date = fields.Datetime(
+ # string='ET Ready to Ship compute',
+ # compute='_compute_etrts_date'
+ # )
expected_ready_to_ship = fields.Datetime(
string='ET Ready to Ship',
copy=False,
@@ -479,16 +479,6 @@ 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
@@ -526,43 +516,55 @@ class SaleOrder(models.Model):
return {'slatime': max_slatime, 'include_instant': include_instant}
- @api.depends("order_line.product_id")
+ @api.depends("order_line.product_id", "date_order")
def _compute_etrts_date(self): #Function to calculate Estimated Ready To Ship Date
- if self.order_line:
- for rec in self:
- max_slatime = 1 # Default SLA jika tidak ada
- slatime = self.calculate_sla_by_vendor(rec.order_line)
- max_slatime = max(max_slatime, slatime['slatime'])
-
- current_date = datetime.now().date()
+ for rec in self:
+ if not rec.date_order:
+ rec.expected_ready_to_ship = False
+ return
+
+ current_date = datetime.now().date()
+
+ max_slatime = 1 # Default SLA jika tidak ada
+ slatime = self.calculate_sla_by_vendor(rec.order_line)
+ max_slatime = max(max_slatime, slatime['slatime'])
- if rec.date_order:
- sum_days = max_slatime + self.get_days_until_next_business_day(current_date) - 1
- if rec.source_id.name != 'Website':
- rec.estimated_arrival_days = sum_days
-
- eta_date = current_date + timedelta(days=sum_days)
- rec.estimated_ready_ship_date = eta_date
- rec.commitment_date = eta_date
- 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):
+ sum_days = max_slatime + self.get_days_until_next_business_day(current_date) - 1
+ if not rec.estimated_arrival_days:
+ rec.estimated_arrival_days = sum_days
+
+ eta_date = current_date + timedelta(days=sum_days)
+ 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
+
+ def _validate_expected_ready_ship_date(self):
for rec in self:
- if rec.expected_ready_to_ship and rec.estimated_ready_ship_date:
+ if rec.expected_ready_to_ship and rec.commitment_date:
+ current_date = datetime.now().date()
# Hanya membandingkan tanggal saja, tanpa jam
expected_date = rec.expected_ready_to_ship.date()
- estimated_date = rec.estimated_ready_ship_date.date()
- if expected_date < estimated_date:
- rec.expected_ready_to_ship = rec.estimated_ready_ship_date
- rec.commitment_date = rec.estimated_ready_ship_date
+ 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
+ eta_minimum = current_date + timedelta(days=sum_days)
+
+ if expected_date < eta_minimum:
+ rec.expected_ready_to_ship = eta_minimum
raise ValidationError(
"Tanggal 'Expected Ready to Ship' tidak boleh lebih kecil dari {}. Mohon pilih tanggal minimal {}."
- .format(estimated_date.strftime('%d-%m-%Y'), estimated_date.strftime('%d-%m-%Y'))
+ .format(eta_minimum.strftime('%d-%m-%Y'), eta_minimum.strftime('%d-%m-%Y'))
)
+ else:
+ rec.commitment_date = rec.expected_ready_to_ship
+
+
+ @api.onchange('expected_ready_to_ship') #Hangle Onchange form Expected Ready to Ship
+ def _onchange_expected_ready_ship_date(self):
+ self._validate_expected_ready_ship_date()
def _set_etrts_date(self):
for order in self:
@@ -1623,6 +1625,7 @@ class SaleOrder(models.Model):
# Ensure partner details are updated when a sale order is created
order = super(SaleOrder, self).create(vals)
order._compute_etrts_date()
+ order._validate_expected_ready_ship_date()
# order._update_partner_details()
return order