diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-10-31 10:17:45 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-10-31 10:17:45 +0700 |
| commit | c1640e45c37e6ab67cd90e2dbc415989a8a4ad45 (patch) | |
| tree | 9ba40e538dc04a30c8b41b4106e4670dc35301a4 | |
| parent | 4bdebe2972657f95b4d40251121c08acef17ab8a (diff) | |
push
| -rw-r--r-- | indoteknik_custom/models/stock_move.py | 117 | ||||
| -rw-r--r-- | indoteknik_custom/views/stock_picking.xml | 8 |
2 files changed, 41 insertions, 84 deletions
diff --git a/indoteknik_custom/models/stock_move.py b/indoteknik_custom/models/stock_move.py index cac88287..43c4676e 100644 --- a/indoteknik_custom/models/stock_move.py +++ b/indoteknik_custom/models/stock_move.py @@ -186,19 +186,9 @@ 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) - 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', + outstanding_qty = fields.Float( + string='Outstanding Qty', + compute='_compute_delivery_line_status', store=False ) delivery_status = fields.Selection([ @@ -206,80 +196,47 @@ class StockMoveLine(models.Model): ('partial', 'Partial'), ('partial_final', 'Partial Final'), ('full', 'Full'), - ], string='Delivery Status', compute='_compute_delivery_status_detail', store=False) + ], string='Delivery Status', compute='_compute_delivery_line_status', store=False) @api.depends('qty_done', 'product_uom_qty', 'picking_id.state') - 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 + def _compute_delivery_line_status(self): + for line in self: + line.outstanding_qty = 0.0 + line.delivery_status = 'none' - if picking.picking_id.name not in ['BU/OUT']: + picking = line.picking_id + if not picking or picking.picking_type_id.code != 'outgoing': continue - move_lines = picking - if not move_lines: - continue + total_qty = line.move_id.product_uom_qty or 0 + done_qty = line.qty_done or 0 - # ====================== - # 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' + line.outstanding_qty = max(total_qty - done_qty, 0) - else: - picking.delivery_status = 'none' + if total_qty == 0: + 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' # Ambil uom dari stock move @api.model diff --git a/indoteknik_custom/views/stock_picking.xml b/indoteknik_custom/views/stock_picking.xml index 288a91c9..78594375 100644 --- a/indoteknik_custom/views/stock_picking.xml +++ b/indoteknik_custom/views/stock_picking.xml @@ -398,10 +398,10 @@ decoration-danger="qty_done>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="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'}}"/> + <field name="qty_yang_mau_dikirim"/> + <field name="qty_terkirim"/> + <field name="qty_gantung"/> + <field name="delivery_status" widget="badge" options="{'colors': {'full': 'success', 'partial': 'warning', 'partial_final': 'danger'}}"/> </tree> </field> </record> |
