summaryrefslogtreecommitdiff
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
parentd0647f4b4a0df94c7b51852823df37eeb5b89e3e (diff)
estimation delerivery date
-rw-r--r--indoteknik_api/controllers/api_v1/product.py18
-rwxr-xr-xindoteknik_custom/models/sale_order.py77
-rwxr-xr-xindoteknik_custom/views/sale_order.xml2
3 files changed, 53 insertions, 44 deletions
diff --git a/indoteknik_api/controllers/api_v1/product.py b/indoteknik_api/controllers/api_v1/product.py
index 5d564ff9..93ef305c 100644
--- a/indoteknik_api/controllers/api_v1/product.py
+++ b/indoteknik_api/controllers/api_v1/product.py
@@ -9,6 +9,17 @@ import json
_logger = logging.getLogger(__name__)
+def get_days_until_next_business_day(start_date=None, *args, **kwargs):
+ today = start_date or datetime.today().date()
+ offset = 0 # Counter jumlah hari yang ditambahkan
+
+ while today.weekday() >= 5 :
+ today += timedelta(days=1)
+ offset += 1
+
+ return offset
+
+
class Product(controller.Controller):
prefix = '/api/v1/'
@@ -75,12 +86,17 @@ class Product(controller.Controller):
if product_sla.sla_vendor_id.unit != 'jam':
include_instant = False
break
+
+ start_date = datetime.today().date()
+ additional_days = get_days_until_next_business_day(start_date)
# Jika semua loop selesai tanpa include_instant menjadi False
return self.response({
'include_instant': include_instant,
'sla_duration': sla_duration,
- 'sla_unit': sla_unit
+ 'sla_additional_days': additional_days,
+ 'sla_total' : int(sla_duration) + int(additional_days),
+ 'sla_unit': 'Hari' if additional_days > 0 else sla_unit
}
)
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"/>