diff options
| -rw-r--r-- | indoteknik_api/controllers/api_v1/sale_order.py | 24 | ||||
| -rw-r--r-- | indoteknik_api/controllers/api_v1/user.py | 4 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 43 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 1 |
4 files changed, 70 insertions, 2 deletions
diff --git a/indoteknik_api/controllers/api_v1/sale_order.py b/indoteknik_api/controllers/api_v1/sale_order.py index 98b13cad..d5208fb1 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 @@ -65,6 +79,7 @@ class SaleOrder(controller.Controller): 'id': sale.id, 'name': sale.name, 'date_order': self.time_to_str(sale.date_order, '%d/%m/%Y %H:%M:%S'), + '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}", 'state': sale.state, 'amount_untaxed': sale.amount_untaxed, 'amount_tax': sale.amount_tax, @@ -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_api/controllers/api_v1/user.py b/indoteknik_api/controllers/api_v1/user.py index b5b7e055..967bbcc9 100644 --- a/indoteknik_api/controllers/api_v1/user.py +++ b/indoteknik_api/controllers/api_v1/user.py @@ -60,7 +60,9 @@ class User(controller.Controller): 'user': self.response_with_token(user), } return self.response(data) - except: + except Exception as e: + respon = str(e) + print(respon) return self.response({ 'is_auth': False, 'reason': 'NOT_FOUND' diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 0d4fc6c3..6ccb6fde 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -303,6 +303,12 @@ class SaleOrder(models.Model): ('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' + ) + + def _compute_total_margin_excl_third_party(self): for order in self: if order.amount_untaxed == 0: @@ -1939,4 +1945,39 @@ class SaleOrder(models.Model): self._validate_delivery_amt() if any(field in vals for field in ["order_line", "client_order_ref"]): self._calculate_etrts_date() - return res
\ No newline at end of file + 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 e0085eeb..5af3f4a2 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -102,6 +102,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" /> |
