summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2025-12-01 15:30:53 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2025-12-01 15:30:53 +0700
commit13502092c296951810b251a6a7277eecd0cade12 (patch)
treec0d7163ea40b120d43f2660349a2783b33a16183
parent7714943d84b320e27223aaac563a86c244580412 (diff)
push ke awal lagi
-rw-r--r--fixco_custom/models/shipment_group.py54
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'