diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-10 09:13:02 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-10 09:13:02 +0700 |
| commit | 64da7e6f4838ba3a5b731609598e6a521d92accd (patch) | |
| tree | a4f479052a9d59a58719e73b2b9ef4443e98bd05 | |
| parent | 31b195e9f678cc6ab40eb3a472c063d5cede1554 (diff) | |
<MIqdad> balikin
| -rw-r--r-- | fixco_custom/models/shipment_group.py | 49 |
1 files changed, 26 insertions, 23 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py index 154db7c..4912ce3 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -267,19 +267,33 @@ 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): - if self.scan_receipt: - exist = self.search([ - '|', - ('scan_receipt', '=', self.scan_receipt), - ('invoice_marketplace', '=', self.scan_receipt), - ], limit=1) + @api.onchange('scan_receipt') + def _check_duplicate_scan(self): + for line in self: + if not line.scan_receipt: + continue - if exist: - raise UserError( - "Receipt '%s' sudah digunakan di shipment group %s." % (self.scan_receipt, exist.shipment_id.number) - ) + # Cari duplikat selain dirinya + dup = self.search([ + ('scan_receipt', '=', line.scan_receipt), + # ('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') @@ -304,17 +318,6 @@ class PickingLine(models.Model): "Receipt '%s' Tidak ditemukan / Status Picking tidak Done." % line.scan_receipt ) - exist = self.search([ - '|', - ('scan_receipt', '=', self.scan_receipt), - ('invoice_marketplace', '=', self.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 |
