summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMqdd <ahmadmiqdad27@gmail.com>2026-01-10 01:21:42 +0700
committerMqdd <ahmadmiqdad27@gmail.com>2026-01-10 01:21:42 +0700
commit31b195e9f678cc6ab40eb3a472c063d5cede1554 (patch)
tree762b61b4d967d501fc7bcb93f945f982b21cb9db
parent82c1232c08894dad3d6e326649785b5669a12077 (diff)
<Miqdad> ngerapihin kode shipment group
-rw-r--r--fixco_custom/models/shipment_group.py49
1 files changed, 23 insertions, 26 deletions
diff --git a/fixco_custom/models/shipment_group.py b/fixco_custom/models/shipment_group.py
index 4912ce3..154db7c 100644
--- a/fixco_custom/models/shipment_group.py
+++ b/fixco_custom/models/shipment_group.py
@@ -267,33 +267,19 @@ 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):
- 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
+ @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)
- # 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 exist:
+ raise UserError(
+ "Receipt '%s' sudah digunakan di shipment group %s." % (self.scan_receipt, exist.shipment_id.number)
+ )
@api.onchange('scan_receipt')
@@ -318,6 +304,17 @@ 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