text: // Copyright (c) 2021, ajan and contributors
  // For license information, please see license.txt
  
  frappe.ui.form.on('Portfolio Template', {
  	setup(frm) {
  		
  		frappe.call({
  			method: "frappe.client.get_value",
  			async:false,
  			args:{
  				doctype:'User',
  				filters:{
  					name:frm.doc.owner
  				},
  				fieldname:['full_name']
  			},
  			callback:function (r) {
  				if(r.message != undefined){
  				    frm.set_value("full_name",r.message.full_name)
  				// 	console.log(r.message.full_name)
  				}
  			}
  		});
  		if(frm.is_new()){
  		    frappe.call({
              method:"frappe.client.get_list",
              args:{
                  doctype:"Instructor Course",
                  filters: [
                      ["instructor","=", frm.doc.full_name]
                  ],
                  fields: ["course","section","academic_year","semester","registered_students","credit_units"],
                  
              },
              callback: function (r) {
                  if (r.message){
                          //setting the table empty, erpnext now has one row by default
                          if(frm.doc.teaching_load){
                              frm.set_value("items",[])
                          }
                          $.each(r.message, function(i, item) {
                              var child = frm.add_child("teaching_load")
                              frappe.model.set_value(child.doctype, child.name, "course_code", item.course);
                              frappe.model.set_value(child.doctype, child.name, "section", item.section);
                              frappe.model.set_value(child.doctype, child.name, "academic_year", item.academic_year);
                              frappe.model.set_value(child.doctype, child.name, "semester", item.semester);
                              frappe.model.set_value(child.doctype, child.name, "number_of_students", item.registered_students);
                              frappe.model.set_value(child.doctype, child.name, "credit_units", item.credit_units);
                              console.log(item, child)
                              frm.refresh_field("teaching_load")
                              // item_row.item_code = item.parent
  					    });
                      }
                  }
              });
  		}
          // frm.refresh()
  	},
  	
      // calculate_score(frm){
      //     // alert("calculating score")
      //     var doc = frm.doc; 
      //     var total_score = doc.teaching_load_score+doc.internship_monitoring_score+doc.research_studies_score;
      //     frm.set_value("portfolio_score_total",total_score)
          
      // },
      
      // before_save(frm){
      //   frm.trigger("calculate_score");
          
      // }
  	
  
  })