summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--indoteknik_api/controllers/api_v1/sale_order.py24
-rwxr-xr-xindoteknik_custom/models/sale_order.py34
-rwxr-xr-xindoteknik_custom/views/sale_order.xml1
3 files changed, 59 insertions, 0 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py
index 98b13cad..e8c2c75a 100644
--- a/indoteknik_api/controllers/api_v1/sale_order.py
+++ b/indoteknik_api/controllers/api_v1/sale_order.py
@@ -54,6 +54,20 @@ class SaleOrder(controller.Controller):
# sales = request.env['sale.order'].search_read([('name', '=', sale_number)], fields=['id', 'name', 'amount_total', 'state'])
sales = request.env['sale.order'].search(query, limit=1)
data = []
+ INDONESIAN_MONTHS = {
+ 1: 'Januari',
+ 2: 'Februari',
+ 3: 'Maret',
+ 4: 'April',
+ 5: 'Mei',
+ 6: 'Juni',
+ 7: 'Juli',
+ 8: 'Agustus',
+ 9: 'September',
+ 10: 'Oktober',
+ 11: 'November',
+ 12: 'Desember',
+ }
for sale in sales:
product_name = ''
product_not_in_id = 0
@@ -69,6 +83,7 @@ class SaleOrder(controller.Controller):
'amount_untaxed': sale.amount_untaxed,
'amount_tax': sale.amount_tax,
'amount_total': sale.amount_total,
+ 'expected_ready_to_ship': f"{sale.expected_ready_to_ship.day} {INDONESIAN_MONTHS[sale.expected_ready_to_ship.month]} {sale.expected_ready_to_ship.year}",
'product_name': product_name,
'product_not_in_id': product_not_in_id,
'details': [request.env['sale.order.line'].api_single_response(x, context='with_detail') for x in sale.order_line]
@@ -142,6 +157,15 @@ class SaleOrder(controller.Controller):
sale_order = request.env['sale.order'].search(domain)
if sale_order:
data = request.env['sale.order'].api_v1_single_response(sale_order, context='with_detail')
+ if sale_order.expected_ready_to_ship:
+ bulan_id = [
+ "Januari", "Februari", "Maret", "April", "Mei", "Juni",
+ "Juli", "Agustus", "September", "Oktober", "November", "Desember"
+ ]
+ tanggal = sale_order.expected_ready_to_ship.day
+ bulan = bulan_id[sale_order.expected_ready_to_ship.month - 1]
+ tahun = sale_order.expected_ready_to_ship.year
+ data['expected_ready_to_ship'] = f"{tanggal} {bulan} {tahun}"
return self.response(data)
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index bdf8f1eb..f89dfb10 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -331,6 +331,10 @@ class SaleOrder(models.Model):
('hold', 'Hold'),
('approve', 'Approve')
], tracking=True, string='State Cancel', copy=False)
+ ready_to_ship_status_detail = fields.Char(
+ string='Status Shipping Detail',
+ compute='_compute_ready_to_ship_status_detail'
+ )
date_hold = fields.Datetime(string='Date Hold', tracking=True, readonly=True, help='Waktu ketika SO di Hold'
)
date_unhold = fields.Datetime(string='Date Unhold', tracking=True, readonly=True, help='Waktu ketika SO di Unhold'
@@ -2008,3 +2012,33 @@ class SaleOrder(models.Model):
if any(field in vals for field in ["order_line", "client_order_ref"]):
self._calculate_etrts_date()
return res
+
+ # @api.depends('commitment_date')
+ def _compute_ready_to_ship_status_detail(self):
+ for order in self:
+ 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
+ product = match.product_id
+ po_line = self.env['purchase.order.line'].search([
+ ('order_id', '=', po.id),
+ ('product_id', '=', product.id)
+ ], limit=1)
+ stock_move = self.env['stock.move'].search([
+ ('purchase_line_id', '=', po_line.id)
+ ], limit=1)
+ picking_in = stock_move.picking_id
+ result_date = picking_in.date_done if picking_in else None
+ if result_date:
+ status = "Early" if result_date < eta else "Delay"
+ 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}"
+ else:
+ order.ready_to_ship_status_detail = "On Track"
+ else:
+ order.ready_to_ship_status_detail = 'On Track' \ No newline at end of file
diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml
index a599a7b8..0fabf279 100755
--- a/indoteknik_custom/views/sale_order.xml
+++ b/indoteknik_custom/views/sale_order.xml
@@ -107,6 +107,7 @@
<t t-esc="' to '"/>
<field name="eta_date" readonly="1"/>
<field name="expected_ready_to_ship"/>
+ <field name="ready_to_ship_status_detail"/>
<field name="flash_sale"/>
<field name="margin_after_delivery_purchase"/>
<field name="percent_margin_after_delivery_purchase"/>