diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-10 13:36:06 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-10 13:36:06 +0700 |
| commit | 23c79946d624f081ef80c57117dba9038569e00a (patch) | |
| tree | e48636bf6bc05251bdad0cc544f9107c4b3b4439 | |
| parent | 0c21e4c4395ab54aa0f4fde0d19a5705dc12cd49 (diff) | |
<Miqdad> push
| -rw-r--r-- | fixco_custom/models/shipment_group.py | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py index ab908a2..36a781b 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -267,20 +267,35 @@ class PickingLine(models.Model): order_reference = fields.Char(string='Order Reference') status = fields.Char(string='Status') - @api.constrains('scan_receipt') - def _check_duplicate_picking_line(self): + @api.onchange('scan_receipt') + def _check_duplicate_scan(self): for line in self: - if self.scan_receipt: - exist = self.search([ - '|', - ('scan_receipt', '=', line.scan_receipt), - ('invoice_marketplace', '=', line.scan_receipt), - ], limit=1) - - if exist: - raise UserError( - "Receipt '%s' sudah digunakan di shipment group %s." % (line.scan_receipt, exist.shipment_id.number) - ) + if not line.scan_receipt: + continue + + # Cari duplikat selain dirinya + dup = self.search([ + '|', + ('scan_receipt', '=', line.scan_receipt), + ('scan_receipt', '=', line.invoice_marketplace), + # ('id', '!=', line.id) + ], limit=1) + + if not dup: + continue + + # 1. Dup di shipment yang sama (lagi create / edit) + # if dup.shipment_id.id == line.shipment_id.id: + # raise ValidationError( + # "Receipt '%s' sudah ada di Shipment ini." % + # line.scan_receipt + # ) + + # 2. Dup di shipment lain (data lama) + raise ValidationError( + "Receipt '%s' sudah digunakan di Shipment %s." % + (line.scan_receipt, dup.shipment_id.number or '-') + ) @api.onchange('scan_receipt') @@ -305,17 +320,6 @@ class PickingLine(models.Model): "Receipt '%s' Tidak ditemukan / Status Picking tidak Done." % line.scan_receipt ) - exist = self.search([ - '|', - ('scan_receipt', '=', line.scan_receipt), - ('invoice_marketplace', '=', line.scan_receipt), - ], limit=1) - - if exist: - raise UserError( - "Receipt '%s' sudah digunakan di shipment group %s." % (line.scan_receipt, exist.shipment_id.number) - ) - # isi field line.picking_id = picking line.carrier = picking.carrier |
