summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/stock_move.py
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-11-19 14:49:01 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-11-19 14:49:01 +0700
commitbb2be920076aabc49b4f9fdd896d14e096e633eb (patch)
tree588196ba53fb7e41d96a61272bdb74b4821fe661 /indoteknik_custom/models/stock_move.py
parent9c4f131ffaf37ca47a78b320a68f7de4e846ecfb (diff)
parent58623e9509789381dbe334969de647b4ad0302a4 (diff)
Merge branch 'odoo-backup' into locatorlocator
# Conflicts: # indoteknik_custom/models/__init__.py # indoteknik_custom/models/stock_move.py # indoteknik_custom/security/ir.model.access.csv # indoteknik_custom/views/stock_picking.xml
Diffstat (limited to 'indoteknik_custom/models/stock_move.py')
-rw-r--r--indoteknik_custom/models/stock_move.py114
1 files changed, 81 insertions, 33 deletions
diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py
index 6622359d..320c175f 100644
--- a/indoteknik_custom/models/stock_move.py
+++ b/indoteknik_custom/models/stock_move.py
@@ -246,52 +246,100 @@ 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',
- store=True
+ 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([
('none', 'No Movement'),
('partial', 'Partial'),
('partial_final', 'Partial Final'),
('full', 'Full'),
- ], string='Delivery Status', compute='_compute_delivery_line_status', store=True)
+ ], 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'
-
- if not line.picking_id or line.picking_id.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 >= total_qty:
- line.delivery_status = 'full'
- elif done_qty < total_qty:
- line.delivery_status = 'partial'
-
- elif 0 < done_qty < total_qty:
- backorder_exists = self.env['stock.picking'].search_count([
- ('group_id', '=', line.picking_id.group_id.id),
- ('name', 'ilike', 'BU/OUT'),
- ('id', '!=', line.picking_id.id),
- ('state', 'in', ['done', 'assigned']),
- ])
-
- if backorder_exists:
- line.delivery_status = 'partial'
- if done_qty >= total_qty:
- line.delivery_status = 'partial_final'
+ # ======================
+ # 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