diff options
| author | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-10 10:19:06 +0700 |
|---|---|---|
| committer | Mqdd <ahmadmiqdad27@gmail.com> | 2026-01-10 10:19:06 +0700 |
| commit | 6e9192ac6f2f4f3e833c1e0872db6e944b6f306a (patch) | |
| tree | 26941a73931d8a0e9c8a08578f2531b6c2f21a29 | |
| parent | 64da7e6f4838ba3a5b731609598e6a521d92accd (diff) | |
<Miqdad> Benerin error singleton sgr
| -rw-r--r-- | fixco_custom/models/shipment_group.py | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py index 4912ce3..ab908a2 100644 --- a/fixco_custom/models/shipment_group.py +++ b/fixco_custom/models/shipment_group.py @@ -267,33 +267,20 @@ class PickingLine(models.Model): order_reference = fields.Char(string='Order Reference') status = fields.Char(string='Status') - @api.onchange('scan_receipt') - def _check_duplicate_scan(self): + @api.constrains('scan_receipt') + def _check_duplicate_picking_line(self): for line in self: - if not line.scan_receipt: - continue - - # 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 '-') - ) + 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) + ) @api.onchange('scan_receipt') @@ -318,6 +305,17 @@ 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 |
