summaryrefslogtreecommitdiff
path: root/indoteknik_custom
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2025-02-07 15:07:01 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2025-02-07 15:07:01 +0700
commit0dbcd5eb060924a0860b2586776f65d5ce19b9ef (patch)
tree9bded0399668761aa60644e3d959038953b54378 /indoteknik_custom
parentd0647f4b4a0df94c7b51852823df37eeb5b89e3e (diff)
estimation delerivery date
Diffstat (limited to 'indoteknik_custom')
-rwxr-xr-xindoteknik_custom/models/sale_order.py77
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
2 files changed, 36 insertions, 43 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index 32e6f11f..cae99447 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -146,10 +146,11 @@ class SaleOrder(models.Model):
])
estimated_ready_ship_date = fields.Datetime(
string='ET Ready to Ship',
- copy=False,
+ compute='_compute_etrts_date',
store=True
+
)
- expected_ready_ship_date = fields.Datetime(
+ expected_ready_to_ship = fields.Datetime(
string='ET Ready to Ship FIX',
copy=False,
store=True
@@ -373,39 +374,29 @@ class SaleOrder(models.Model):
rec.compute_fullfillment = True
+ @api.depends('date_order', 'estimated_arrival_days', 'state')
def _compute_eta_date(self):
- max_leadtime = 0
-
- for line in self.order_line:
- leadtime = line.vendor_id.leadtime
- max_leadtime = max(max_leadtime, leadtime)
-
- for rec in self:
- if rec.date_order and rec.state not in ['cancel', 'draft']:
- eta_date = datetime.now() + timedelta(days=max_leadtime)
- rec.eta_date = eta_date
+ for rec in self:
+ if rec.date_order and rec.state not in ['cancel'] and rec.estimated_arrival_days:
+ rec.eta_date = rec.date_order + timedelta(days=rec.estimated_arrival_days)
else:
rec.eta_date = False
- def _compute_etrts_date(self):
- max_slatime = 100
-
- # untuk setiap produk dalam so di ambil sla nya sla paling kecil itulah yang dipakai untuk tambah ke
- max_leadtime = 0
-
- for line in self.order_line:
- product_sla = self.env['product.sla'].search([('product_variant_id', '=', line.product_id.id)])
- slatime = int(product_sla.sla) or 1
- max_slatime = max(max_slatime, slatime)
-
+ @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)
+ slatime = int(product_sla.sla) if product_sla and product_sla.sla else 1
+ max_slatime = max(max_slatime, slatime)
+
if rec.date_order:
eta_date = datetime.now() + timedelta(days=max_slatime)
rec.estimated_ready_ship_date = eta_date
- if not rec.expected_ready_ship_date:
- rec.expected_ready_ship_date = eta_date
- # else:
- # rec.estimated_ready_ship_date = False
+ # Jika expected_ready_to_ship kosong, set nilai default
+ if not rec.expected_ready_to_ship:
+ rec.expected_ready_to_ship = eta_date
def _set_etrts_date(self):
for order in self:
@@ -413,19 +404,6 @@ class SaleOrder(models.Model):
raise UserError(_("You cannot change the Estimated Ready To Ship Date on a done, sale or cancelled order."))
# order.move_lines.write({'estimated_ready_ship_date': order.estimated_ready_ship_date})
- @api.onchange('estimated_ready_ship_date')
- def _onchange_estimated_ready_ship_date(self):
- for record in self:
- if (record.estimated_ready_ship_date and record.expected_ready_ship_date):
- if(record.estimated_ready_ship_date < record.expected_ready_ship_date):
- return {
- 'warning': {
- 'title': _('Requested date is too soon.'),
- 'message': _("The delivery date is sooner than the expected date."
- "You may be unable to honor the delivery date.")
- }
- }
-
def _prepare_invoice(self):
"""
Prepare the dict of values to create the new invoice for a sales order. This method may be
@@ -619,6 +597,21 @@ class SaleOrder(models.Model):
if line.product_id.type == 'product':
line_no += 1
line.line_no = line_no
+
+ @api.onchange('expected_ready_to_ship') #Hangle Onchange form Expected Ready to Ship
+ def _onchange_expected_ready_ship_date(self):
+ for rec in self:
+ if rec.expected_ready_to_ship and rec.estimated_ready_ship_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
+ 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'))
+ )
def write(self, vals):
res = super(SaleOrder, self).write(vals)
@@ -627,7 +620,7 @@ class SaleOrder(models.Model):
for picking in self.picking_ids:
if picking.state == 'assigned':
picking.carrier_id = self.carrier_id
-
+
return res
def calculate_so_status(self):
@@ -1433,7 +1426,7 @@ class SaleOrder(models.Model):
def create(self, vals):
# Ensure partner details are updated when a sale order is created
order = super(SaleOrder, self).create(vals)
- order._compute_etrts_date()
+ # order._compute_etrts_date()
# order._update_partner_details()
return order
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index 09a71912..74fc6e54 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -69,7 +69,7 @@
</field>
<field name="tag_ids" position="after">
<field name="eta_date" readonly="1"/>
- <field name="estimated_ready_ship_date" />
+ <field name="expected_ready_to_ship" />
<field name="flash_sale"/>
<field name="margin_after_delivery_purchase"/>
<field name="percent_margin_after_delivery_purchase"/>