Merge pull request #3793 from nabinhait/serial_no

Validate serial no in return entry with against document
This commit is contained in:
Anand Doshi 2015-08-04 14:45:30 +05:30
commit 950250d444
4 changed files with 1231 additions and 86 deletions

View File

@ -8,7 +8,6 @@ from frappe.utils import flt, get_datetime, format_datetime
class StockOverReturnError(frappe.ValidationError): pass
def validate_return(doc):
if not doc.meta.get_field("is_return") or not doc.is_return:
return
@ -50,13 +49,15 @@ def validate_return_against(doc):
.format(doc.return_against))
def validate_returned_items(doc):
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
valid_items = frappe._dict()
for d in frappe.db.sql("""select item_code, sum(qty) as qty, rate from `tab{0} Item`
for d in frappe.db.sql("""select item_code, sum(qty) as qty, rate, serial_no, batch_no from `tab{0} Item`
where parent = %s group by item_code""".format(doc.doctype), doc.return_against, as_dict=1):
valid_items.setdefault(d.item_code, d)
if doc.doctype in ("Delivery Note", "Sales Invoice"):
for d in frappe.db.sql("""select item_code, sum(qty) as qty from `tabPacked Item`
for d in frappe.db.sql("""select item_code, sum(qty) as qty, serial_no, batch_no from `tabPacked Item`
where parent = %s group by item_code""".format(doc.doctype), doc.return_against, as_dict=1):
valid_items.setdefault(d.item_code, d)
@ -81,8 +82,20 @@ def validate_returned_items(doc):
elif ref.rate and flt(d.rate) != ref.rate:
frappe.throw(_("Row # {0}: Rate must be same as {1} {2}")
.format(d.idx, doc.doctype, doc.return_against))
elif ref.batch_no and d.batch_no != ref.batch_no:
frappe.throw(_("Row # {0}: Batch No must be same as {1} {2}")
.format(d.idx, doc.doctype, doc.return_against))
elif ref.serial_no:
if not d.serial_no:
frappe.throw(_("Row # {0}: Serial No is mandatory").format(d.idx))
else:
serial_nos = get_serial_nos(d.serial_no)
ref_serial_nos = get_serial_nos(ref.serial_no)
for s in serial_nos:
if s not in ref_serial_nos:
frappe.throw(_("Row # {0}: Serial No {1} does not match with {2} {3}")
.format(d.idx, s, doc.doctype, doc.return_against))
items_returned = True
if not items_returned:
@ -134,7 +147,7 @@ def make_return_doc(doctype, source_name, target_doc=None):
},
doctype +" Item": {
"doctype": doctype + " Item",
"fields": {
"field_map": {
"purchase_order": "purchase_order",
"purchase_receipt": "purchase_receipt",
"serial_no": "serial_no",

View File

@ -218,7 +218,9 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
item.serial_no += sr_no[x] + '\n';
refresh_field("serial_no", item.name, item.parentfield);
frappe.model.set_value(item.doctype, item.name, "qty", sr_no.length);
if(!doc.is_return) {
frappe.model.set_value(item.doctype, item.name, "qty", sr_no.length);
}
}
}
},

View File

@ -83,7 +83,7 @@ $.extend(erpnext, {
return {
filters: {
item_code:grid_row.doc.item_code ,
warehouse:grid_row.doc.warehouse
warehouse:cur_frm.doc.is_return ? null : grid_row.doc.warehouse
}
}
}

File diff suppressed because it is too large Load Diff