Column not found

Hi

We have made a new module which is BOQ and it consists of 4 tables. My problem is that whenver I input something at the 1st table it works fine however if I input something more 1 table it sends me errors.
Below is the script:

frappe.ui.form.on(“BOQ”, “onload”, function(frm, cdt, cdn, doc, dt, dn){
frm.add_fetch(“item_code”, “description”, “description”);
frm.add_fetch(“item_code”, “item_name”, “item_name”);
frm.add_fetch(“item_code”, “stock_uom”, “stock_uom”);
frm.add_fetch(“item_code”, “item_group”, “item_group”);
});
//First Table
frappe.ui.form.on(“Bill of Materials Item”, “total_buying_cost”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
grand_total = 0;
$.each(frm.doc.items || [], function(i, d) {
grand_total += flt(d.total_buying_cost);
});
frm.set_value(“grand_total”, grand_total);
});
frappe.ui.form.on(“Bill of Materials Item”, “total_selling_cost”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
selling_cost_total = 0;
$.each(frm.doc.items || [], function(i, d) {
selling_cost_total += flt(d.total_selling_cost);
});
frm.set_value(“selling_cost_total”, selling_cost_total);
});
frappe.ui.form.on(“Bill of Materials Item”, “price_list_rate”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_buying_cost = 0;
$.each(frm.doc.items || [], function(i, d) {
total_buying_cost = flt(d.price_list_rate * d.qty);
});
frappe.model.set_value(cdt, cdn, “total_buying_cost”, total_buying_cost);
});
frappe.ui.form.on(“Bill of Materials Item”, “item_selling”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_selling_cost = 0;
$.each(frm.doc.items || [], function(i, d) {
total_selling_cost = flt(d.item_selling * d.qty);
});
frappe.model.set_value(cdt, cdn, “total_selling_cost”, total_selling_cost);
});
//Second Table
frappe.ui.form.on(“Bill of Materials Item 2”, “total_buying_cost2”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
grand_total2 = 0;
$.each(frm.doc.items2 || [], function(i, d) {
grand_total2 += flt(d.total_buying_cost2);
});
frm.set_value(“grand_total2”, grand_total2);
});
frappe.ui.form.on(“Bill of Materials Item 2”, “total_selling_cost2”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
selling_cost_total_2 = 0;
$.each(frm.doc.items2 || [], function(i, d) {
selling_cost_total_2 += flt(d.total_selling_cost2);
});
frm.set_value(“selling_cost_total_2”, selling_cost_total_2);
});
frappe.ui.form.on(“Bill of Materials Item 2”, “price_list_rate2”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_buying_cost2 = 0;
$.each(frm.doc.items2 || [], function(i, d) {
total_buying_cost2 = flt(d.price_list_rate2 * d.qty2);
});
frappe.model.set_value(cdt, cdn, “total_buying_cost2”, total_buying_cost2);
});
frappe.ui.form.on(“Bill of Materials Item 2”, “item_selling2”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_selling_cost = 0;
$.each(frm.doc.items2 || [], function(i, d) {
total_selling_cost2 = flt(d.item_selling2 * d.qty2);
});
frappe.model.set_value(cdt, cdn, “total_selling_cost2”, total_selling_cost2);
});
//Third Table
frappe.ui.form.on(“Bill of Materials Item 3”, “total_buying_cost”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
grand_total3 = 0;
$.each(frm.doc.items3 || [], function(i, d) {
grand_total3 += flt(d.total_buying_cost);
});
frm.set_value(“grand_total3”, grand_total3);
});
frappe.ui.form.on(“Bill of Materials Item 3”, “total_selling_cost3”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
selling_cost_total_3 = 0;
$.each(frm.doc.items3 || [], function(i, d) {
selling_cost_total_3 += flt(d.total_selling_cost3);
});
frm.set_value(“selling_cost_total_3”, selling_cost_total_3);
});
frappe.ui.form.on(“Bill of Materials Item 3”, “price_list_rate”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_buying_cost = 0;
$.each(frm.doc.items3 || [], function(i, d) {
total_buying_cost = flt(d.price_list_rate * d.qty);
});
frappe.model.set_value(cdt, cdn, “total_buying_cost”, total_buying_cost);
});
frappe.ui.form.on(“Bill of Materials Item 3”, “item_selling”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_selling_cost = 0;
$.each(frm.doc.items3 || [], function(i, d) {
total_selling_cost = flt(d.item_selling * d.qty);
});
frappe.model.set_value(cdt, cdn, “total_selling_cost3”, total_selling_cost3);
});
// Fourth Table
frappe.ui.form.on(“Bill of Materials Item 4”, “total_buying_cost”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
grand_total4 = 0;
$.each(frm.doc.items4 || [], function(i, d) {
grand_total4 += flt(d.total_buying_cost);
});
frm.set_value(“grand_total4”, grand_total4);
});
frappe.ui.form.on(“Bill of Materials Item 4”, “total_selling_cost”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
selling_cost_total_4 = 0;
$.each(frm.doc.items4 || [], function(i, d) {
selling_cost_total_4 += flt(d.total_selling_cost);
});
frm.set_value(“selling_cost_total_4”, selling_cost_total_4);
});
frappe.ui.form.on(“Bill of Materials Item 4”, “price_list_rate”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_buying_cost = 0;
$.each(frm.doc.items4 || [], function(i, d) {
total_buying_cost = flt(d.price_list_rate * d.qty);
});
frappe.model.set_value(cdt, cdn, “total_buying_cost”, total_buying_cost);
});
frappe.ui.form.on(“Bill of Materials Item 4”, “item_selling”, function(frm, cdt, cdn) {
// code for calculate total and set on parent field.
total_selling_cost = 0;
$.each(frm.doc.items4 || [], function(i, d) {
total_selling_cost = flt(d.item_selling * d.qty);
});
frappe.model.set_value(cdt, cdn, “total_selling_cost”, total_selling_cost);
});

Please refer to the attached pictures for the errors and doctype


can you share the full traceback ?

@makarand_b Please refer below:

Traceback (innermost last):
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/desk/form/save.py”, line 18, in savedocs
doc.save()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/document.py”, line 258, in save
self.update_children()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/document.py”, line 269, in update_children
d.db_update()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/base_document.py”, line 308, in db_update
self.db_insert()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/base_document.py”, line 282, in db_insert
), d.values())
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/database.py”, line 136, in sql
self._cursor.execute(query, values)
File “/home/frappe/press/benches/1606241046/env/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/frappe/press/benches/1606241046/env/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1054, “Unknown column ‘total_selling_cost’ in ‘field list’”)

Traceback (innermost last):
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/app.py”, line 57, in application
response = frappe.handler.handle()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/handler.py”, line 19, in handle
execute_cmd(cmd)
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/handler.py”, line 36, in execute_cmd
ret = frappe.call(method, **frappe.form_dict)
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/init.py”, line 806, in call
return fn(*args, **newargs)
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/desk/form/save.py”, line 18, in savedocs
doc.save()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/document.py”, line 258, in save
self.update_children()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/document.py”, line 269, in update_children
d.db_update()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/base_document.py”, line 308, in db_update
self.db_insert()
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/model/base_document.py”, line 282, in db_insert
), d.values())
File “/home/frappe/press/benches/1606241046/apps/frappe/frappe/database.py”, line 136, in sql
self._cursor.execute(query, values)
File “/home/frappe/press/benches/1606241046/env/lib/python2.7/site-packages/MySQLdb/cursors.py”, line 205, in execute
self.errorhandler(self, exc, value)
File “/home/frappe/press/benches/1606241046/env/lib/python2.7/site-packages/MySQLdb/connections.py”, line 36, in defaulterrorhandler
raise errorclass, errorvalue
OperationalError: (1054, “Unknown column ‘total_selling_cost’ in ‘field list’”)

Hi,

please check if you have the total_selling_cost field in BOQ doctype, if not create the field and try again.

Thanks, Makarand

Hi @makarand_b I have it at a table. I got 4 tables so I have 4 total_selling_cost.