I have Custom doctype repairing In that doctype i have one child table which include machine and there details like serial number and brand and etc.
i want to make script for if same machine (match serial number with previous records) come for repair then script increase the number by 1 in repair count field (child table field)
i tried with this but it not working properly some time it is giving error like
pymysql.err.OperationalError: (1054, "Unknown column ‘serial_number’ in ‘where clause’
import frappe
@frappe.whitelist()
def get_repair_count(serial_number, current_date, parent_docname):
# Query the parent records with earlier dates
repair_records = frappe.get_all('Repairing',
filters={'date': ['<', current_date], 'name': ['!=', parent_docname]},
fields=['name']
)
count = 0
for record in repair_records:
child_records = frappe.get_all('Repairing Product',
filters={'parent': record.name, 'serial_number': serial_number},
fields=['serial_number']
)
count += len(child_records)
return count
frappe.ui.form.on('Repairing', {
before_save: function(frm) {
let serialNumbers = frm.doc.product.map(d => d.serial_number).filter(sn => sn);
let currentDate = frm.doc.date || new Date();
let parentDocname = frm.doc.name;
// Iterate over each serial number to get the repair count
serialNumbers.forEach(serialNumber => {
frappe.call({
method: 'ce.ce.doctype.repairing.repairing.get_repair_count',
args: {
serial_number: serialNumber,
current_date: currentDate,
parent_docname: parentDocname
},
callback: function(response) {
let existingRecordCount = response.message || 0;
// Update each row in the child table that matches the serial number
frm.doc.product.forEach(row => {
if (row.serial_number === serialNumber) {
row.repair_count = existingRecordCount;
}
});
// Refresh the child table to reflect changes
frm.refresh_field('product');
}
});
});
}
});
any one have solution for this ?