fix: not able to make serial and batch using csv import (#38659) (cherry picked from commit 89a0e9c2453ba4eef4158477db537771cdc9ed70) Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
parent
b0675f6490
commit
dd07ecad45
@ -121,7 +121,7 @@ frappe.ui.form.on('Serial and Batch Bundle', {
|
|||||||
frappe.throw(__("Please attach CSV file"));
|
frappe.throw(__("Please attach CSV file"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (frm.doc.has_serial_no && !prompt_data.using_csv_file && !prompt_data.serial_nos) {
|
if (frm.doc.has_serial_no && !prompt_data.csv_file && !prompt_data.serial_nos) {
|
||||||
frappe.throw(__("Please enter serial nos"));
|
frappe.throw(__("Please enter serial nos"));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@ -506,6 +506,22 @@ class SerialandBatchBundle(Document):
|
|||||||
serial_batches = {}
|
serial_batches = {}
|
||||||
|
|
||||||
for row in self.entries:
|
for row in self.entries:
|
||||||
|
if self.has_serial_no and not row.serial_no:
|
||||||
|
frappe.throw(
|
||||||
|
_("At row {0}: Serial No is mandatory for Item {1}").format(
|
||||||
|
bold(row.idx), bold(self.item_code)
|
||||||
|
),
|
||||||
|
title=_("Serial No is mandatory"),
|
||||||
|
)
|
||||||
|
|
||||||
|
if self.has_batch_no and not row.batch_no:
|
||||||
|
frappe.throw(
|
||||||
|
_("At row {0}: Batch No is mandatory for Item {1}").format(
|
||||||
|
bold(row.idx), bold(self.item_code)
|
||||||
|
),
|
||||||
|
title=_("Batch No is mandatory"),
|
||||||
|
)
|
||||||
|
|
||||||
if row.serial_no:
|
if row.serial_no:
|
||||||
serial_nos.append(row.serial_no)
|
serial_nos.append(row.serial_no)
|
||||||
|
|
||||||
@ -789,6 +805,9 @@ def parse_csv_file_to_get_serial_batch(reader):
|
|||||||
if index == 0:
|
if index == 0:
|
||||||
has_serial_no = row[0] == "Serial No"
|
has_serial_no = row[0] == "Serial No"
|
||||||
has_batch_no = row[0] == "Batch No"
|
has_batch_no = row[0] == "Batch No"
|
||||||
|
if not has_batch_no:
|
||||||
|
has_batch_no = row[1] == "Batch No"
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not row[0]:
|
if not row[0]:
|
||||||
@ -805,6 +824,13 @@ def parse_csv_file_to_get_serial_batch(reader):
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
batch_nos.append(
|
||||||
|
{
|
||||||
|
"batch_no": row[1],
|
||||||
|
"qty": row[2],
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
serial_nos.append(_dict)
|
serial_nos.append(_dict)
|
||||||
elif has_batch_no:
|
elif has_batch_no:
|
||||||
batch_nos.append(
|
batch_nos.append(
|
||||||
@ -840,6 +866,9 @@ def make_serial_nos(item_code, serial_nos):
|
|||||||
serial_nos_details = []
|
serial_nos_details = []
|
||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
for serial_no in serial_nos:
|
for serial_no in serial_nos:
|
||||||
|
if frappe.db.exists("Serial No", serial_no):
|
||||||
|
continue
|
||||||
|
|
||||||
serial_nos_details.append(
|
serial_nos_details.append(
|
||||||
(
|
(
|
||||||
serial_no,
|
serial_no,
|
||||||
@ -870,7 +899,7 @@ def make_serial_nos(item_code, serial_nos):
|
|||||||
|
|
||||||
frappe.db.bulk_insert("Serial No", fields=fields, values=set(serial_nos_details))
|
frappe.db.bulk_insert("Serial No", fields=fields, values=set(serial_nos_details))
|
||||||
|
|
||||||
frappe.msgprint(_("Serial Nos are created successfully"))
|
frappe.msgprint(_("Serial Nos are created successfully"), alert=True)
|
||||||
|
|
||||||
|
|
||||||
def make_batch_nos(item_code, batch_nos):
|
def make_batch_nos(item_code, batch_nos):
|
||||||
@ -881,6 +910,9 @@ def make_batch_nos(item_code, batch_nos):
|
|||||||
batch_nos_details = []
|
batch_nos_details = []
|
||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
for batch_no in batch_nos:
|
for batch_no in batch_nos:
|
||||||
|
if frappe.db.exists("Batch", batch_no):
|
||||||
|
continue
|
||||||
|
|
||||||
batch_nos_details.append(
|
batch_nos_details.append(
|
||||||
(batch_no, batch_no, now(), now(), user, user, item.item_code, item.item_name, item.description)
|
(batch_no, batch_no, now(), now(), user, user, item.item_code, item.item_name, item.description)
|
||||||
)
|
)
|
||||||
@ -899,7 +931,7 @@ def make_batch_nos(item_code, batch_nos):
|
|||||||
|
|
||||||
frappe.db.bulk_insert("Batch", fields=fields, values=set(batch_nos_details))
|
frappe.db.bulk_insert("Batch", fields=fields, values=set(batch_nos_details))
|
||||||
|
|
||||||
frappe.msgprint(_("Batch Nos are created successfully"))
|
frappe.msgprint(_("Batch Nos are created successfully"), alert=True)
|
||||||
|
|
||||||
|
|
||||||
def parse_serial_nos(data):
|
def parse_serial_nos(data):
|
||||||
|
|||||||
@ -27,7 +27,6 @@
|
|||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
"label": "Serial No",
|
"label": "Serial No",
|
||||||
"mandatory_depends_on": "eval:parent.has_serial_no == 1",
|
|
||||||
"options": "Serial No",
|
"options": "Serial No",
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
@ -38,7 +37,6 @@
|
|||||||
"in_list_view": 1,
|
"in_list_view": 1,
|
||||||
"in_standard_filter": 1,
|
"in_standard_filter": 1,
|
||||||
"label": "Batch No",
|
"label": "Batch No",
|
||||||
"mandatory_depends_on": "eval:parent.has_batch_no == 1",
|
|
||||||
"options": "Batch",
|
"options": "Batch",
|
||||||
"search_index": 1
|
"search_index": 1
|
||||||
},
|
},
|
||||||
@ -122,7 +120,7 @@
|
|||||||
"index_web_pages_for_search": 1,
|
"index_web_pages_for_search": 1,
|
||||||
"istable": 1,
|
"istable": 1,
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2023-07-03 15:29:50.199075",
|
"modified": "2023-12-10 19:47:48.227772",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "Stock",
|
"module": "Stock",
|
||||||
"name": "Serial and Batch Entry",
|
"name": "Serial and Batch Entry",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user