diff options
| author | Indoteknik . <it@fixcomart.co.id> | 2025-06-19 09:24:39 +0700 |
|---|---|---|
| committer | Indoteknik . <it@fixcomart.co.id> | 2025-06-19 09:24:39 +0700 |
| commit | 89a53c90bfeb735f3f256dfadfd24c5c5a5c6328 (patch) | |
| tree | d5073990177d80d43d2df393386f9390698a78fa | |
| parent | df8995b1bca8cc55622621e73d46069507f09540 (diff) | |
(andri) penambahan ET product leadtime berdasarkan SLA vendor tanpa logistik & hari libur
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 41 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 9 |
2 files changed, 50 insertions, 0 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index ee9d6f70..7607d4ca 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 (SLA Vendor)', 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 DO dengan prefix BU/PICK/ yang sudah 'assigned' dan memiliki reserved date." + ) + + @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': diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index d0442677..861006cc 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -144,6 +144,15 @@ <field name="date_doc_kirim" readonly="1"/> <field name="notification" readonly="1"/> </field> + <xpath expr="//page[@name='other_information']/group/group[@name='sale_reporting']" position="after"> + <group string="ETA"> + <field name="et_products"/> + <field name="eta_date_reserved"/> + <field name="expected_ready_to_ship"/> + <field name="eta_date_start"/> + <field name="eta_date" readonly="1"/> + </group> + </xpath> <xpath expr="//form/sheet/notebook/page/field[@name='order_line']" position="attributes"> <attribute name="attrs"> |
