diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-08-20 16:20:02 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-08-20 16:20:02 +0700 |
| commit | c5cd456da8f679664437995636eac4f634f3ad94 (patch) | |
| tree | 7f3082dbd736ccff78da2e7da450b7b9109cfdd7 | |
| parent | 398945636b3318ed02749f63028f8f76d2d2060d (diff) | |
| parent | af483feb734c1e135a779008ca3fa32a721d59ff (diff) | |
Merge branch 'odoo-backup' of https://bitbucket.org/altafixco/indoteknik-addons into odoo-backup
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 35 | ||||
| -rw-r--r-- | indoteknik_custom/models/sale_order_line.py | 23 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 22 | ||||
| -rwxr-xr-x | indoteknik_custom/views/sale_order.xml | 2 |
4 files changed, 48 insertions, 34 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 53be999f..5787c6ea 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -431,21 +431,27 @@ class SaleOrder(models.Model): continue for move in line.move_ids: - if move.state != 'done': - # reserve qty (draft/assigned) - if move.picking_type_id.code == 'internal': + if move.picking_type_id.code == 'internal': + if move.state != 'done': + # PICK belum done → qty reserved reserved_qty += move.reserved_availability or 0.0 - continue - - # sudah done → cek alur lokasi - if move.location_dest_id.usage == 'customer': - # barang keluar → delivered - delivered_qty += move.quantity_done - elif move.location_id.usage == 'customer': - # barang balik (return) → kurangi delivered - delivered_qty -= move.quantity_done - - # clamp biar ga minus + else: + # PICK done → qty_done masih dianggap reserved (masuk BU/OUT) + reserved_qty += move.quantity_done or 0.0 + + elif move.state == 'done': + # OUT done (customer terima) → delivered + if move.location_dest_id.usage == 'customer': + delivered_qty += move.quantity_done + # sekaligus kurangi reserved (karena udah terkirim) + reserved_qty -= move.quantity_done + # Return dari customer + elif move.location_id.usage == 'customer': + delivered_qty -= move.quantity_done + reserved_qty += move.quantity_done # balik ke reserved + + # clamp jangan sampai minus + reserved_qty = max(reserved_qty, 0) delivered_qty = max(delivered_qty, 0) order.reserved_percent = (reserved_qty / total_qty) * 100 @@ -455,6 +461,7 @@ class SaleOrder(models.Model): order.reserved_percent = order.delivered_percent = order.unreserved_percent = 0 + def _has_ccm(self): if self.id: self.ccm_id = self.env['tukar.guling'].search([('origin', 'ilike', self.name)], limit=1) diff --git a/indoteknik_custom/models/sale_order_line.py b/indoteknik_custom/models/sale_order_line.py index 2406995d..a20f93ef 100644 --- a/indoteknik_custom/models/sale_order_line.py +++ b/indoteknik_custom/models/sale_order_line.py @@ -66,21 +66,29 @@ class SaleOrderLine(models.Model): if order_qty > 0: for move in line.move_ids: + # --- CASE 1: Picking belum done --- if move.state != 'done': - # Reserve qty (hanya dari picking internal yang belum selesai) if move.picking_type_id.code == 'internal': reserved_qty += move.reserved_availability or 0.0 continue - # Kalau sudah done → cek lokasi - if move.location_dest_id.usage == 'customer': - # Barang keluar → tambah delivered + # --- 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 + elif move.location_id.usage == 'customer': - # Barang balik dari customer (retur) → kurangi delivered + # Retur dari customer delivered_qty -= move.quantity_done + reserved_qty += move.quantity_done - # Jangan sampai delivered minus + # clamp supaya gak minus + reserved_qty = max(reserved_qty, 0) delivered_qty = max(delivered_qty, 0) # Hitung persentase @@ -88,9 +96,6 @@ class SaleOrderLine(models.Model): line.delivered_percent = (delivered_qty / order_qty) * 100 if order_qty else 0 line.unreserved_percent = 100 - line.reserved_percent - line.delivered_percent - - - def _get_outgoing_incoming_moves(self): outgoing_moves = self.env['stock.move'] incoming_moves = self.env['stock.move'] diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index 3d04a416..423cbb0a 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -1330,18 +1330,20 @@ class StockPicking(models.Model): current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.date_reserved = current_time + # Validate Qty Demand Can't higher than Qty Product - for move_line in self.move_line_ids_without_package: - purchase_line = move_line.move_id.purchase_line_id - if purchase_line: - if purchase_line.product_uom_qty < move_line.product_uom_qty: - raise UserError( - _("Quantity demand (%s) tidak bisa lebih besar dari qty product (%s) untuk produk %s") % ( - move_line.product_uom_qty, - purchase_line.product_uom_qty, - move_line.product_id.display_name + if self.location_dest_id.id == 58 and 'BU/INPUT/' in self.name: + for move in self.move_ids_without_package: + purchase_line = move.purchase_line_id + if purchase_line: + if purchase_line.product_qty < move.quantity_done: + raise UserError( + _("Quantity demand (%s) tidak bisa lebih besar dari qty product (%s) untuk produk %s") % ( + move.quantity_done, + purchase_line.product_qty, + move.product_id.display_name + ) ) - ) self.validation_minus_onhand_quantity() self.responsible = self.env.user.id diff --git a/indoteknik_custom/views/sale_order.xml b/indoteknik_custom/views/sale_order.xml index be31456b..0a99fe3a 100755 --- a/indoteknik_custom/views/sale_order.xml +++ b/indoteknik_custom/views/sale_order.xml @@ -486,7 +486,7 @@ <field name="payment_state_custom" widget="badge" decoration-danger="payment_state_custom == 'unpaid'" decoration-success="payment_state_custom == 'paid'" - decoration-warning="payment_state_custom == 'partial'"/> + decoration-warning="payment_state_custom == 'partial'" optional="hide"/> <field name="unreserved_percent" widget="percentpie" string="Unreserved"/> <field name="reserved_percent" widget="percentpie" string="Reserved"/> <field name="delivered_percent" widget="percentpie" string="Delivered"/> |
