summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-10-31 10:19:09 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-10-31 10:19:09 +0700
commit47b3591071225983cfec5d76497efe5cceae0af6 (patch)
tree83a6d22610820e62914a3035f708ac4ffb8fff71
parentc1640e45c37e6ab67cd90e2dbc415989a8a4ad45 (diff)
push
-rw-r--r--indoteknik_custom/models/stock_move.py117
1 files changed, 80 insertions, 37 deletions
diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py
index 43c4676e..cac88287 100644
--- a/indoteknik_custom/models/stock_move.py
+++ b/indoteknik_custom/models/stock_move.py
@@ -186,9 +186,19 @@ class StockMoveLine(models.Model):
line_no = fields.Integer('No', default=0)
note = fields.Char('Note')
manufacture = fields.Many2one('x_manufactures', string="Brands", related="product_id.x_manufacture", store=True)
- outstanding_qty = fields.Float(
- string='Outstanding Qty',
- compute='_compute_delivery_line_status',
+ qty_yang_mau_dikirim = fields.Float(
+ string='Qty yang Mau Dikirim',
+ compute='_compute_delivery_status_detail',
+ store=False
+ )
+ qty_terkirim = fields.Float(
+ string='Qty Terkirim',
+ compute='_compute_delivery_status_detail',
+ store=False
+ )
+ qty_gantung = fields.Float(
+ string='Qty Gantung',
+ compute='_compute_delivery_status_detail',
store=False
)
delivery_status = fields.Selection([
@@ -196,47 +206,80 @@ class StockMoveLine(models.Model):
('partial', 'Partial'),
('partial_final', 'Partial Final'),
('full', 'Full'),
- ], string='Delivery Status', compute='_compute_delivery_line_status', store=False)
+ ], string='Delivery Status', compute='_compute_delivery_status_detail', store=False)
@api.depends('qty_done', 'product_uom_qty', 'picking_id.state')
- def _compute_delivery_line_status(self):
- for line in self:
- line.outstanding_qty = 0.0
- line.delivery_status = 'none'
-
- picking = line.picking_id
- if not picking or picking.picking_type_id.code != 'outgoing':
+ def _compute_delivery_status_detail(self):
+ for picking in self:
+ # Default values
+ picking.qty_yang_mau_dikirim = 0.0
+ picking.qty_terkirim = 0.0
+ picking.qty_gantung = 0.0
+ picking.delivery_status = 'none'
+
+ # Hanya berlaku untuk pengiriman (BU/OUT)
+ if picking.picking_id.picking_type_id.code != 'outgoing':
continue
- total_qty = line.move_id.product_uom_qty or 0
- done_qty = line.qty_done or 0
-
- line.outstanding_qty = max(total_qty - done_qty, 0)
+ if picking.picking_id.name not in ['BU/OUT']:
+ continue
- if total_qty == 0:
+ move_lines = picking
+ if not move_lines:
continue
- if done_qty == 0:
- line.delivery_status = 'none'
- elif done_qty > 0:
- has_other_out = 0
- if picking.group_id and isinstance(picking.id, int):
- has_other_out = self.env['stock.picking'].search_count([
- ('group_id', '=', picking.group_id.id),
- ('name', 'ilike', 'BU/OUT'),
- ('id', '!=', picking.id),
- ('state', '=', 'done'),
- ])
- if has_other_out and done_qty == total_qty:
- line.delivery_status = 'partial_final'
- elif not has_other_out and done_qty >= total_qty:
- line.delivery_status = 'full'
- elif has_other_out and done_qty < total_qty:
- line.delivery_status = 'partial'
- elif done_qty < total_qty:
- line.delivery_status = 'partial'
- else:
- line.delivery_status = 'none'
+ # ======================
+ # HITUNG QTY
+ # ======================
+ total_qty = move_lines.product_uom_qty
+
+ done_qty_total = move_lines.move_id.sale_line_id.qty_delivered
+ order_qty_total = move_lines.move_id.sale_line_id.product_uom_qty
+ gantung_qty_total = order_qty_total - done_qty_total - total_qty
+
+ picking.qty_yang_mau_dikirim = total_qty
+ picking.qty_terkirim = done_qty_total
+ picking.qty_gantung = gantung_qty_total
+
+ # if total_qty == 0:
+ # picking.delivery_status = 'none'
+ # continue
+
+ # if done_qty_total == 0:
+ # picking.delivery_status = 'none'
+ # continue
+
+ # ======================
+ # CEK BU/OUT LAIN (BACKORDER)
+ # ======================
+ # has_other_out = self.env['stock.picking'].search_count([
+ # ('group_id', '=', picking.group_id.id),
+ # ('name', 'ilike', 'BU/OUT'),
+ # ('id', '!=', picking.id),
+ # ('state', 'in', ['assigned', 'waiting', 'confirmed', 'done']),
+ # ])
+
+ # ======================
+ # LOGIKA STATUS
+ # ======================
+ if gantung_qty_total == 0 and done_qty_total == 0:
+ # Semua barang udah terkirim, ga ada picking lain
+ picking.delivery_status = 'full'
+
+ elif gantung_qty_total > 0 and total_qty > 0 and done_qty_total == 0:
+ # Masih ada picking lain dan sisa gantung → proses masih jalan
+ picking.delivery_status = 'partial'
+
+ # elif gantung_qty_total > 0:
+ # # Ini picking terakhir, tapi qty belum full
+ # picking.delivery_status = 'partial_final'
+
+ elif gantung_qty_total == 0 and done_qty_total > 0 and total_qty > 0:
+ # Udah kirim semua tapi masih ada picking lain (rare case)
+ picking.delivery_status = 'partial_final'
+
+ else:
+ picking.delivery_status = 'none'
# Ambil uom dari stock move
@api.model