summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-10-31 10:13:52 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-10-31 10:13:52 +0700
commit4bdebe2972657f95b4d40251121c08acef17ab8a (patch)
treed7f16653a1dcfb937e66c06eaef49b5ceb3e802d
parent2a57a75b636128cda3d1ee321a926643c461dacf (diff)
big fux
-rwxr-xr-xindoteknik_custom/models/sale_order.py2
-rw-r--r--indoteknik_custom/models/stock_move.py117
-rw-r--r--indoteknik_custom/models/stock_picking.py15
-rw-r--r--indoteknik_custom/views/stock_picking.xml6
4 files changed, 93 insertions, 47 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py
index b8de1697..1eba2808 100755
--- a/indoteknik_custom/models/sale_order.py
+++ b/indoteknik_custom/models/sale_order.py
@@ -2722,8 +2722,6 @@ class SaleOrder(models.Model):
if self.env.context.get("ask_approval") and user.id in (3401, 20, 3988):
return True
-
-
salesperson_id = self.user_id.id
approver_id = user.id
team_leader_id = self.team_id.user_id.id
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
diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py
index 7f8523a3..273fda82 100644
--- a/indoteknik_custom/models/stock_picking.py
+++ b/indoteknik_custom/models/stock_picking.py
@@ -212,6 +212,9 @@ class StockPicking(models.Model):
if picking.picking_type_id.code != 'outgoing':
continue
+ if picking.name not in ['BU/OUT']:
+ continue
+
move_lines = picking.move_line_ids_without_package
if not move_lines:
continue
@@ -240,12 +243,12 @@ class StockPicking(models.Model):
# ======================
# 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']),
- ])
+ # 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
diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml
index 050fc819..288a91c9 100644
--- a/indoteknik_custom/views/stock_picking.xml
+++ b/indoteknik_custom/views/stock_picking.xml
@@ -398,8 +398,10 @@
decoration-danger="qty_done&gt;product_uom_qty and state!='done' and parent.picking_type_code != 'incoming'"
decoration-success="qty_done==product_uom_qty and state!='done' and not result_package_id">
<field name="note" placeholder="Add a note here"/>
- <field name="outstanding_qty"/>
- <field name="delivery_status" widget="badge" options="{'colors': {'full': 'success', 'partial': 'warning', 'partial_final': 'danger'}}"/>
+ <field name="qty_yang_mau_dikirim" attrs="{'invisible': ['|', ('parent.name', '=', False), ('parent.name', 'not', ['BU/OUT/'])]}"/>
+ <field name="qty_terkirim" attrs="{'invisible': ['|', ('parent.name', '=', False), ('parent.name', 'not', ['BU/OUT/'])]}"/>
+ <field name="qty_gantung" attrs="{'invisible': ['|', ('parent.name', '=', False), ('parent.name', 'not', ['BU/OUT/'])]}"/>
+ <field name="delivery_status" attrs="{'invisible': ['|', ('parent.name', '=', False), ('parent.name', 'not', ['BU/OUT/'])]}" widget="badge" options="{'colors': {'full': 'success', 'partial': 'warning', 'partial_final': 'danger'}}"/>
</tree>
</field>
</record>