diff options
| author | IT Fixcomart <it@fixcomart.co.id> | 2025-06-19 02:44:25 +0000 |
|---|---|---|
| committer | IT Fixcomart <it@fixcomart.co.id> | 2025-06-19 02:44:25 +0000 |
| commit | 347dde6c03a623e36796ebc03b6b18aa00b93b9d (patch) | |
| tree | ff05f189e95e04823d67bfa29b901bf27d9913d6 /indoteknik_custom/models | |
| parent | 393228f1b25d3fa460d8300c45642e66edbca88a (diff) | |
| parent | c4640e2f846d853412c5f1cb0901e50208fa0216 (diff) | |
Merged in et_product (pull request #338)
Et product
Diffstat (limited to 'indoteknik_custom/models')
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index ee9d6f70..6da46398 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -349,6 +349,47 @@ class SaleOrder(models.Model): date_unhold = fields.Datetime(string='Date Unhold', tracking=True, readonly=True, help='Waktu ketika SO di Unhold' ) + et_products = fields.Datetime(string='ET Products', compute='_compute_et_products', help="Leadtime produk berdasarkan SLA vendor, tanpa logistik.") + + eta_date_reserved = fields.Datetime( + string="Date Reserved", + compute="_compute_eta_date_reserved", + help="Tanggal pertama kali barang berhasil di-reservasi pada DO (BU/PICK/) yang berstatus Siap Dikirim." + ) + + @api.depends('order_line.product_id', 'date_order') + def _compute_et_products(self): + jakarta = pytz.timezone("Asia/Jakarta") + for order in self: + if not order.order_line or not order.date_order: + order.et_products = False + continue + + # Ambil tanggal order sebagai basis + base_date = order.date_order + if base_date.tzinfo is None: + base_date = jakarta.localize(base_date) + else: + base_date = base_date.astimezone(jakarta) + + # Ambil nilai SLA vendor dalam hari + sla_data = order.calculate_sla_by_vendor(order.order_line) + sla_days = sla_data.get('slatime', 1) + + # Hitung ETA produk (tanpa logistik) + eta_datetime = base_date + timedelta(days=sla_days) + + # Simpan ke field sebagai UTC-naive datetime (standar Odoo) + order.et_products = eta_datetime.astimezone(pytz.utc).replace(tzinfo=None) + + @api.depends('picking_ids.state', 'picking_ids.date_reserved') + def _compute_eta_date_reserved(self): + for order in self: + pickings = order.picking_ids.filtered( + lambda p: p.state == 'assigned' and p.date_reserved and 'BU/PICK/' in (p.name or '') + ) + order.eta_date_reserved = min(pickings.mapped('date_reserved')) if pickings else False + @api.onchange('shipping_cost_covered') def _onchange_shipping_cost_covered(self): if self.shipping_cost_covered == 'indoteknik' and self.select_shipping_option == 'biteship': |
