diff options
Diffstat (limited to 'fixco_custom/models/shipment_group.py')
| -rw-r--r-- | fixco_custom/models/shipment_group.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py index 766bd75..b69d932 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -195,19 +195,24 @@ class PickingLine(models.Model): for line in self: scan = (line.scan_receipt or "").strip() if not scan: - return + continue - # 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) + mem_dupes = line.shipment_id.picking_lines.filtered( + lambda l: l.scan_receipt == scan and l != line + ) + if mem_dupes and 'virtual' not in mem_dupes.id.ref: + raise UserError("Receipt '%s' already exists in this form." % scan) + + if line.shipment_id.id: + db_dupes = self.env['picking.line'].search([ + ('shipment_id', '=', line.shipment_id.id), + ('scan_receipt', '=', scan), + ('id', '!=', line.id or 0), + ], limit=1) - if duplicate: - raise UserError("Receipt '%s' already exists." % scan) + if db_dupes: + raise UserError("Receipt '%s' already exists in database." % scan) - # Ambil picking by tracking number picking = self.env['stock.picking'].search([ ('tracking_number', '=', scan) ], limit=1) @@ -220,7 +225,6 @@ class PickingLine(models.Model): line.order_reference = picking.order_reference line.invoice_marketplace = picking.invoice_mp - class ProductShipmentLine(models.Model): _name = 'product.shipment.line' _description = 'Product Shipment Line' |
