From 119273639c14cc89bddc45f402f6c2d8c8abc8f3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 5 Sep 2023 16:21:33 +0530 Subject: [PATCH] fix: added validation for unique serial numbers in pos invoice (#36302) fix: added validation for unique serial numbers in pos invoice (#36302) * fix: added validation for unique serial numbers in pos invoice * fix: updated title of validation * fix: removed extra whitespace * fix: added validation for duplicate batch numbers --------- Co-authored-by: Ritvik Sardana (cherry picked from commit a165b37fd73f6b68f17c19f7e537e08ba035bb2f) Co-authored-by: RitvikSardana <65544983+RitvikSardana@users.noreply.github.com> --- .../doctype/pos_invoice/pos_invoice.py | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py index 0ff230bb18b..e7a7ae24ceb 100644 --- a/erpnext/accounts/doctype/pos_invoice/pos_invoice.py +++ b/erpnext/accounts/doctype/pos_invoice/pos_invoice.py @@ -1,6 +1,6 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors and contributors # For license information, please see license.txt - +import collections import frappe from frappe import _ @@ -43,6 +43,7 @@ class POSInvoice(SalesInvoice): self.validate_debit_to_acc() self.validate_write_off_account() self.validate_change_amount() + self.validate_duplicate_serial_and_batch_no() self.validate_change_account() self.validate_item_cost_centers() self.validate_warehouse() @@ -155,6 +156,27 @@ class POSInvoice(SalesInvoice): title=_("Item Unavailable"), ) + def validate_duplicate_serial_and_batch_no(self): + serial_nos = [] + batch_nos = [] + + for row in self.get("items"): + if row.serial_no: + serial_nos = row.serial_no.split("\n") + + if row.batch_no and not row.serial_no: + batch_nos.append(row.batch_no) + + if serial_nos: + for key, value in collections.Counter(serial_nos).items(): + if value > 1: + frappe.throw(_("Duplicate Serial No {0} found").format("key")) + + if batch_nos: + for key, value in collections.Counter(batch_nos).items(): + if value > 1: + frappe.throw(_("Duplicate Batch No {0} found").format("key")) + def validate_pos_reserved_batch_qty(self, item): filters = {"item_code": item.item_code, "warehouse": item.warehouse, "batch_no": item.batch_no}