How to save document object via JS?

I am trying to create and submit a Journal Entry on the cancel of a Payment Entry. Here is the custom script but I am unable to save and/or submit the new Journal Entry onto database.

frappe.ui.form.on("Payment Entry", {
	before_cancel: function(frm) {
		debugger;
		if (frm.doc.penalty_amount > 0 && frm.doc.cheque_status == "Bounced")
		{
			debugger;
			var jv_doc = frappe.model.get_new_doc("Journal Entry");
			jv_doc.company = frm.doc.company;
			jv_doc.posting_date = frappe.datetime.now_date();
			jv_doc.cheque_no = frm.doc.reference_no;
			jv_doc.cheque_date = frm.doc.reference_date;
			// Row for Debtor
			var jv_row = frappe.model.add_child(jv_doc, "Journal Entry Account", "accounts");
			jv_row.account = frappe.db.get_value("Company", jv_doc.company, "default_receivable_account");
			jv_row.party = frm.doc.party;
			jv_row.debit_in_account_currency = frm.doc.penalty_amount;
			// Row for Cash account
			var jv_row1 = frappe.model.add_child(jv_doc, "Journal Entry Account", "accounts");
			jv_row1.account = frappe.db.get_value("Company", jv_doc.company, "default_cash_account");
			jv_row1.credit_in_account_currency = frm.doc.penalty_amount;
            jv_doc.save() #THIS DOESN'T WORK
		}
	}
});

What error are you getting?
You can write the hook in python.

The function does not exist.

You can write the hook in python.

I guess I will have to do the same

Can you post the trace?

try insert() method instead of save().

Shall I use jv_doc.insert() at end ? It gave me an error that there is no such function.

Or better I can go via the Python route

Python route is better