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 (#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 <ritviksardana@Ritviks-MacBook-Air.local>
(cherry picked from commit a165b37)

Co-authored-by: RitvikSardana <65544983+RitvikSardana@users.noreply.github.com>
  • Loading branch information
mergify[bot] and RitvikSardana authored Sep 5, 2023
1 parent fc79af5 commit 1192736
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 @@ -43,6 +43,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 @@ -155,6 +156,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 1192736

Please sign in to comment.