Skip to content

Commit

Permalink
fix: added validation for unique serial numbers in pos invoice (#36302)
Browse files Browse the repository at this point in the history
* 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 <ritviksardana@Ritviks-MacBook-Air.local>
  • Loading branch information
RitvikSardana and Ritvik Sardana committed Jul 31, 2023
1 parent cdc86bd commit a165b37
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion erpnext/accounts/doctype/pos_invoice/pos_invoice.py
Original file line number Diff line number Diff line change
@@ -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 _
Expand Down Expand Up @@ -44,6 +44,7 @@ def validate(self):
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()
Expand Down Expand Up @@ -154,6 +155,27 @@ def validate_pos_reserved_serial_nos(self, item):
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}

Expand Down

0 comments on commit a165b37

Please sign in to comment.