mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-30 18:34:48 +00:00
fix: list index out of range (#21614)
This commit is contained in:
@@ -7,7 +7,7 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.model.naming import make_autoname, revert_series_if_last
|
from frappe.model.naming import make_autoname, revert_series_if_last
|
||||||
from frappe.utils import flt, cint
|
from frappe.utils import flt, cint, get_link_to_form
|
||||||
from frappe.utils.jinja import render_template
|
from frappe.utils.jinja import render_template
|
||||||
from frappe.utils.data import add_days
|
from frappe.utils.data import add_days
|
||||||
from six import string_types
|
from six import string_types
|
||||||
@@ -124,7 +124,7 @@ class Batch(Document):
|
|||||||
if has_expiry_date and not self.expiry_date:
|
if has_expiry_date and not self.expiry_date:
|
||||||
frappe.throw(msg=_("Please set {0} for Batched Item {1}, which is used to set {2} on Submit.") \
|
frappe.throw(msg=_("Please set {0} for Batched Item {1}, which is used to set {2} on Submit.") \
|
||||||
.format(frappe.bold("Shelf Life in Days"),
|
.format(frappe.bold("Shelf Life in Days"),
|
||||||
frappe.utils.get_link_to_form("Item", self.item),
|
get_link_to_form("Item", self.item),
|
||||||
frappe.bold("Batch Expiry Date")),
|
frappe.bold("Batch Expiry Date")),
|
||||||
title=_("Expiry Date Mandatory"))
|
title=_("Expiry Date Mandatory"))
|
||||||
|
|
||||||
@@ -264,16 +264,20 @@ def get_batch_no(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
|||||||
def get_batches(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
def get_batches(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
||||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||||
cond = ''
|
cond = ''
|
||||||
if serial_no:
|
if serial_no and frappe.get_cached_value('Item', item_code, 'has_batch_no'):
|
||||||
|
serial_nos = get_serial_nos(serial_no)
|
||||||
batch = frappe.get_all("Serial No",
|
batch = frappe.get_all("Serial No",
|
||||||
fields = ["distinct batch_no"],
|
fields = ["distinct batch_no"],
|
||||||
filters= {
|
filters= {
|
||||||
"item_code": item_code,
|
"item_code": item_code,
|
||||||
"warehouse": warehouse,
|
"warehouse": warehouse,
|
||||||
"name": ("in", get_serial_nos(serial_no))
|
"name": ("in", serial_nos)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if not batch:
|
||||||
|
validate_serial_no_with_batch(serial_nos, item_code)
|
||||||
|
|
||||||
if batch and len(batch) > 1:
|
if batch and len(batch) > 1:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -288,4 +292,15 @@ def get_batches(item_code, warehouse, qty=1, throw=False, serial_no=None):
|
|||||||
and (`tabBatch`.expiry_date >= CURDATE() or `tabBatch`.expiry_date IS NULL) {0}
|
and (`tabBatch`.expiry_date >= CURDATE() or `tabBatch`.expiry_date IS NULL) {0}
|
||||||
group by batch_id
|
group by batch_id
|
||||||
order by `tabBatch`.expiry_date ASC, `tabBatch`.creation ASC
|
order by `tabBatch`.expiry_date ASC, `tabBatch`.creation ASC
|
||||||
""".format(cond), (item_code, warehouse), as_dict=True)
|
""".format(cond), (item_code, warehouse), as_dict=True)
|
||||||
|
|
||||||
|
def validate_serial_no_with_batch(serial_nos, item_code):
|
||||||
|
if frappe.get_cached_value("Serial No", serial_nos[0], "item_code") != item_code:
|
||||||
|
frappe.throw(_("The serial no {0} does not belong to item {1}")
|
||||||
|
.format(get_link_to_form("Serial No", serial_nos[0]), get_link_to_form("Item", item_code)))
|
||||||
|
|
||||||
|
serial_no_link = ','.join([get_link_to_form("Serial No", sn) for sn in serial_nos])
|
||||||
|
|
||||||
|
message = "Serial Nos" if len(serial_nos) > 1 else "Serial No"
|
||||||
|
frappe.throw(_("There is no batch found against the {0}: {1}")
|
||||||
|
.format(message, serial_no_link))
|
||||||
Reference in New Issue
Block a user