diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-01 14:36:38 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2025-12-01 14:36:38 +0700 |
| commit | ebf6bdf833e7e07d7c7b677c8855416ba447f725 (patch) | |
| tree | 3812a038d650efc174e08aa33aaa3f2bc23e3b29 | |
| parent | 15377b23022440d88c40c656a513b3397ba43e9a (diff) | |
push fix scan receipt shipment group
| -rw-r--r-- | fixco_custom/models/shipment_group.py | 48 |
1 files changed, 26 insertions, 22 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py index b6ffbda..766bd75 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -193,29 +193,33 @@ class PickingLine(models.Model): @api.onchange('scan_receipt') def _onchange_scan_receipt(self): for line in self: - if line.scan_receipt: - lines = line.shipment_id.picking_lines.filtered( - lambda p_lines: p_lines.scan_receipt == line.scan_receipt - ) + scan = (line.scan_receipt or "").strip() + if not scan: + return + + # Cek dari database (aman dari NewId) + duplicate = self.env['picking.line'].search([ + ('shipment_id', '=', line.shipment_id.id), + ('scan_receipt', '=', scan), + ('id', '!=', line.id or 0), # exclude diri sendiri kalau sudah ada ID + ], limit=1) + + if duplicate: + raise UserError("Receipt '%s' already exists." % scan) + + # Ambil picking by tracking number + picking = self.env['stock.picking'].search([ + ('tracking_number', '=', scan) + ], limit=1) + + if not picking: + raise UserError("Receipt '%s' not found." % scan) + + line.picking_id = picking + line.carrier = picking.carrier + line.order_reference = picking.order_reference + line.invoice_marketplace = picking.invoice_mp - if lines: - raise UserError(( - "Receipt '%s' already exists. " - ) % line.scan_receipt) - - picking = self.env['stock.picking'].search([ - ('tracking_number', '=', line.scan_receipt) - ], limit=1) - - if not picking: - raise UserError(( - "Receipt '%s' not found. " - ) % line.scan_receipt) - - line.picking_id = picking - line.carrier = picking.carrier - line.order_reference = picking.order_reference - line.invoice_marketplace = picking.invoice_mp class ProductShipmentLine(models.Model): _name = 'product.shipment.line' |
