Restrict Parent BOM Code based on a condition of Child Part

Hi Everyone,
I have a requirement that, I want to restrict the Parent Item Code based on the Child Item Code.
Requirement is, If any child part is serial controlled then its parent should be serial controlled and system should not allow the BOM to save. However, I have written a code, but its giving error.

Below is my code:

frappe.ui.form.on("BOM", "validate", function(frm, doctype, name) {

    for(var idx in frm.doc.items) {
if (frm.doc.items[idx].has_serial_no=1) {
if(frm.doc.has_serial_no=0)
{
msgprint("BOM Code should be marked as Serial Controlled as there is/are part(s) in the BOM is are serial controlled");
validated=false;       
     }}
    }
});

[09/03/2016 17:30:17] Ruchin Sharma: Here is the error:
[09/03/2016 17:30:18] Ruchin Sharma: Traceback (innermost last):
File “/home/sam/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 18, in savedocs
doc.save()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 231, in save
self.insert()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 194, in insert
self._validate()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 338, in _validate
self._validate_links()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 528, in _validate_links
result = d.get_invalid_links(is_submittable=self.meta.is_submittable)
File “/home/sam/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 414, in get_invalid_links
value = frappe.db.get_value(doctype, docname, “name”, cache=True)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 397, in get_value
ret = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug, cache=cache)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 438, in get_values
out = self._get_values_from_table(fields, filters, doctype, as_dict, debug, order_by, update)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 545, in _get_values_from_table
conditions, values = self.build_conditions(filters)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 363, in build_conditions
for f in filters:
TypeError: ‘int’ object is not iterable

Traceback (innermost last):
File “/home/sam/frappe-bench/apps/frappe/frappe/app.py”, line 57, in application
response = frappe.handler.handle()
File “/home/sam/frappe-bench/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/sam/frappe-bench/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/sam/frappe-bench/apps/frappe/frappe/init.py”, line 806, in call
return fn(*args, **newargs)
File “/home/sam/frappe-bench/apps/frappe/frappe/desk/form/save.py”, line 18, in savedocs
doc.save()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 231, in save
self.insert()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 194, in insert
self._validate()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 338, in _validate
self._validate_links()
File “/home/sam/frappe-bench/apps/frappe/frappe/model/document.py”, line 528, in _validate_links
result = d.get_invalid_links(is_submittable=self.meta.is_submittable)
File “/home/sam/frappe-bench/apps/frappe/frappe/model/base_document.py”, line 414, in get_invalid_links
value = frappe.db.get_value(doctype, docname, “name”, cache=True)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 397, in get_value
ret = self.get_values(doctype, filters, fieldname, ignore, as_dict, debug, cache=cache)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 438, in get_values
out = self._get_values_from_table(fields, filters, doctype, as_dict, debug, order_by, update)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 545, in _get_values_from_table
conditions, values = self.build_conditions(filters)
File “/home/sam/frappe-bench/apps/frappe/frappe/database.py”, line 363, in build_conditions
for f in filters:
TypeError: ‘int’ object is not iterable

I appreciate, if anyone can help me in this context.

Regards
Ruchin Sharma

Hi,
I have resolved the problem, by my own.
Actually the problem was due to link field.
Actually, I noticed that I have taken has_serial_no field in BOM and BOM Item but wrongly I mentioned its (has_serial_no field) type as link, whereas it should be check.

Regards
Ruchin Sharma

1 Like