diff options
Diffstat (limited to 'fixco_custom/models/shipment_group.py')
| -rw-r--r-- | fixco_custom/models/shipment_group.py | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py index b427bcd..b6ffbda 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -193,43 +193,29 @@ class PickingLine(models.Model): @api.onchange('scan_receipt') def _onchange_scan_receipt(self): for line in self: - scan = (line.scan_receipt or "").strip() - if not scan: - continue - - # === 1. Cek duplikat di memory (record yang belum save) === - mem_dupes = line.shipment_id.picking_lines.filtered( - lambda l: l is not line and - (l.id.ref == None) and - l.scan_receipt == scan and not self - ) - if mem_dupes: - raise UserError("Receipt '%s' already exists (unsaved)." % scan) - - # === 2. Cek duplikat di database === - if line.shipment_id.id: - db_dupes = self.env['picking.line'].search([ - ('shipment_id', '=', line.shipment_id.id), - ('scan_receipt', '=', scan), - ('id', '!=', line._origin.id or 0), - ], limit=1) - - if db_dupes: - raise UserError("Receipt '%s' already exists." % scan) - - # === 3. Cek tracking number di stock.picking === - picking = self.env['stock.picking'].search([ - ('tracking_number', '=', scan) - ], limit=1) + if line.scan_receipt: + lines = line.shipment_id.picking_lines.filtered( + lambda p_lines: p_lines.scan_receipt == line.scan_receipt + ) - if not picking: - raise UserError("Receipt '%s' not found." % scan) + if lines: + raise UserError(( + "Receipt '%s' already exists. " + ) % line.scan_receipt) + + picking = self.env['stock.picking'].search([ + ('tracking_number', '=', line.scan_receipt) + ], limit=1) - line.picking_id = picking - line.carrier = picking.carrier - line.order_reference = picking.order_reference - line.invoice_marketplace = picking.invoice_mp + 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' |
