diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-08-22 10:48:43 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-08-22 10:48:43 +0700 |
| commit | 3b71cb2bb18f72e48c6f5013576a66ae982321da (patch) | |
| tree | 3c28d353ceceb676461e8bd627b5851efb7d7f61 | |
| parent | dab315df817429db7a8445f4dd08c9722e4d328a (diff) | |
fix bug percent pie sale order line
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index a20f93ef..47a24264 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -58,7 +58,12 @@ class SaleOrderLine(models.Model): delivered_percent = fields.Float(string="Delivered %", digits=(16, 2), compute="_compute_reserved_delivered_pie", store=False) unreserved_percent = fields.Float(string="Unreserved %", digits=(16, 2), compute="_compute_reserved_delivered_pie", store=False) - @api.depends('move_ids.state', 'move_ids.reserved_availability', 'move_ids.quantity_done') + @api.depends( + 'move_ids.state', + 'move_ids.reserved_availability', + 'move_ids.quantity_done', + 'move_ids.picking_type_id' + ) def _compute_reserved_delivered_pie(self): for line in self: order_qty = line.product_uom_qty or 0.0 @@ -66,35 +71,26 @@ class SaleOrderLine(models.Model): if order_qty > 0: for move in line.move_ids: - # --- CASE 1: Picking belum done --- - if move.state != 'done': - if move.picking_type_id.code == 'internal': - reserved_qty += move.reserved_availability or 0.0 + # --- CASE 1: Move belum selesai --- + if move.state not in ('done', 'cancel'): + reserved_qty += move.reserved_availability or 0.0 continue - # --- CASE 2: Picking sudah done --- - if move.picking_type_id.code == 'internal': - # PICK done → qty_done tetap dianggap reserved (masih nunggu OUT) - reserved_qty += move.quantity_done or 0.0 - - elif move.location_dest_id.usage == 'customer': - # OUT done (barang nyampe customer) - delivered_qty += move.quantity_done - reserved_qty -= move.quantity_done - + # --- CASE 2: Move sudah done --- + if move.location_dest_id.usage == 'customer': + # Barang dikirim ke customer + delivered_qty += move.quantity_done or 0.0 elif move.location_id.usage == 'customer': - # Retur dari customer - delivered_qty -= move.quantity_done - reserved_qty += move.quantity_done + # Barang balik dari customer (retur) + delivered_qty -= move.quantity_done or 0.0 - # clamp supaya gak minus - reserved_qty = max(reserved_qty, 0) + # Clamp supaya delivered gak minus delivered_qty = max(delivered_qty, 0) - # Hitung persentase - line.reserved_percent = (reserved_qty / order_qty) * 100 if order_qty else 0 - line.delivered_percent = (delivered_qty / order_qty) * 100 if order_qty else 0 - line.unreserved_percent = 100 - line.reserved_percent - line.delivered_percent + # Hitung persen + line.reserved_percent = min((reserved_qty / order_qty) * 100, 100) if order_qty else 0 + line.delivered_percent = min((delivered_qty / order_qty) * 100, 100) if order_qty else 0 + line.unreserved_percent = max(100 - line.reserved_percent - line.delivered_percent, 0) def _get_outgoing_incoming_moves(self): outgoing_moves = self.env['stock.move'] |
