Error when click on button and then click on printer icon to print

Hello;
I am facing this error only when I need to print the document and after I clicked on button that run js and py scripts:

"Document attached to child table must be a dict or BaseDocument, not " + str(type(value))[1:-1]
ValueError: Document attached to child table must be a dict or BaseDocument, not type ‘list’

In my py script, I used db sql and in the js I converted some values to float because I need to do arithmetic calculations. So what is the solution?

Note: if I need to print the document and I did not click on the button, there is no errors appear.

Regards
Bilal

@bghayad can you share your script for the same??

OK, I am going to share part of the script but it contains the main idea:

.js:

frappe.ui.form.on(‘R10 Periodic Declaration’, {
refresh: function(frm) {

    },
    calculate: function(frm) {
            if (frm.doc.from_period){
                    frappe.call({
                            method: "erpnext.hr.doctype.r10_periodic_declaration.r10_periodic_declaration.calculate_board_no",
                            args: {
                            from_period: frm.doc.from_period,
                            to_period: frm.doc.to_period
                            },
                            callback: function(r) {
                                    if (r.message) {
                                    cur_frm.set_value("board_salaries_and_peripherals", r.message);
                                    }
                            }
                    });
                    };
            }
    });

.py:

from future import unicode_literals
import frappe
from frappe.model.document import Document
from frappe import _, msgprint

class R10PeriodicDeclaration(Document):
pass

@frappe.whitelist()
def calculate_board_no(from_period, to_period):

     SUM_TA_board = 0
     SUM_RC_board = 0
     SUM_CC_board = 0
     SUM_FC_board = 0

     SUM_SwPFCSS_board =  frappe.db.sql("""
            select sum(amount) as total
            from `tabSalary Detail`
            where parent in (select name from `tabSalary Slip`
            where employee in (select employee from tabEmployee where employment_type like %(emp_type)s)
            and start_date >= %(from_date)s)
            and abbr = 'SwPFCSS'
            """, {"emp_type": "Board%", "from_date": from_period})

     return SUM_SwPFCSS_board

Regards
Bilal

Note:

If I used as_dict=True in the sql query, then the error disappear.
Any help how to overcome this error without need to use as_dict=True?
Again, it is appearing only when I need to print. So, what is the relation between this error and the print?

Regards
Bilal