fix: Clean Serial No input on Server Side

This commit is contained in:
marination 2021-07-22 13:23:54 +05:30
parent fd12f65047
commit f22b858253
5 changed files with 18 additions and 3 deletions

View File

@ -27,6 +27,7 @@ class StockController(AccountsController):
if not self.get('is_return'): if not self.get('is_return'):
self.validate_inspection() self.validate_inspection()
self.validate_serialized_batch() self.validate_serialized_batch()
self.clean_serial_nos()
self.validate_customer_provided_item() self.validate_customer_provided_item()
self.set_rate_of_stock_uom() self.set_rate_of_stock_uom()
self.validate_internal_transfer() self.validate_internal_transfer()
@ -72,6 +73,12 @@ class StockController(AccountsController):
frappe.throw(_("Row #{0}: The batch {1} has already expired.") frappe.throw(_("Row #{0}: The batch {1} has already expired.")
.format(d.idx, get_link_to_form("Batch", d.get("batch_no")))) .format(d.idx, get_link_to_form("Batch", d.get("batch_no"))))
def clean_serial_nos(self):
for row in self.get("items"):
if hasattr(row, "serial_no") and row.serial_no:
# replace commas by linefeed and remove all spaces in string
row.serial_no = row.serial_no.replace(",", "\n").replace(" ", "")
def get_gl_entries(self, warehouse_account=None, default_expense_account=None, def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
default_cost_center=None): default_cost_center=None):

View File

@ -732,7 +732,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
this.frm.trigger("item_code", cdt, cdn); this.frm.trigger("item_code", cdt, cdn);
} }
else { else {
// Replacing all occurences of comma with carriage return // Replace all occurences of comma with line feed
item.serial_no = item.serial_no.replace(/,/g, '\n'); item.serial_no = item.serial_no.replace(/,/g, '\n');
item.conversion_factor = item.conversion_factor || 1; item.conversion_factor = item.conversion_factor || 1;
refresh_field("serial_no", item.name, item.parentfield); refresh_field("serial_no", item.name, item.parentfield);

View File

@ -165,8 +165,14 @@ class SerialNo(StockController):
) )
ORDER BY ORDER BY
posting_date desc, posting_time desc, creation desc""", posting_date desc, posting_time desc, creation desc""",
(self.item_code, self.company, (
serial_no, serial_no+'\n%', '%\n'+serial_no, '%\n'+serial_no+'\n%'), as_dict=1): self.item_code, self.company,
serial_no,
serial_no+'\n%',
'%\n'+serial_no,
'%\n'+serial_no+'\n%'
),
as_dict=1):
if serial_no.upper() in get_serial_nos(sle.serial_no): if serial_no.upper() in get_serial_nos(sle.serial_no):
if cint(sle.actual_qty) > 0: if cint(sle.actual_qty) > 0:
sle_dict.setdefault("incoming", []).append(sle) sle_dict.setdefault("incoming", []).append(sle)

View File

@ -76,6 +76,7 @@ class StockEntry(StockController):
self.validate_difference_account() self.validate_difference_account()
self.set_job_card_data() self.set_job_card_data()
self.set_purpose_for_stock_entry() self.set_purpose_for_stock_entry()
self.clean_serial_nos()
self.validate_duplicate_serial_no() self.validate_duplicate_serial_no()
if not self.from_bom: if not self.from_bom:

View File

@ -31,6 +31,7 @@ class StockReconciliation(StockController):
self.validate_expense_account() self.validate_expense_account()
self.validate_customer_provided_item() self.validate_customer_provided_item()
self.set_zero_value_for_customer_provided_items() self.set_zero_value_for_customer_provided_items()
self.clean_serial_nos()
self.set_total_qty_and_amount() self.set_total_qty_and_amount()
self.validate_putaway_capacity() self.validate_putaway_capacity()