I’m trying get an doctype and delete it, but nothing is happening. I have an child table in Purchase Invoice form, and I’m getting ‘serie_parcela’ docfield value for each row. Each Titulo form has this value too in ‘ref_parcela’ docfield, so i use this to do a get_doc and delete it.
JS:
//Deleting Titulos on Purchase Invoice cancel
frappe.ui.form.on("Purchase Invoice", "on_cancel", function(frm) {
$.each(frm.doc.parcelas || [], function (i, d) {
frappe.call({
method: "financeiro.financeiro.doctype.titulos.titulos.delete_titulo",
args: {
serie_parcela: d.serie_parcela,
},
callback: function(r){
console.log(r.message)
}
});
});
});
PY:
@frappe.whitelist()
def delete_titulo(serie_parcela):
titulos = frappe.get_doc({
"doctype" : "Titulos",
"ref_parcela" : serie_parcela
})
delete = frappe.delete_doc(titulos)
return delete
Leonardo_Augusto:
delete_doc
You aren’t using delete doc correctly. You just need to pass the doctype and the docname, not the whole doc.
@frappe.whitelist()
def delete_titulo(serie_parcela):
delete = frappe.delete_doc("Titulos",serie_parcela)
return delete
import frappe
import unittest
test_records = frappe.get_test_records('Item Attribute')
from erpnext.stock.doctype.item_attribute.item_attribute import ItemAttributeIncrementError
class TestItemAttribute(unittest.TestCase):
def setUp(self):
if frappe.db.exists("Item Attribute", "_Test_Length"):
frappe.delete_doc("Item Attribute", "_Test_Length")
def test_numeric_item_attribute(self):
item_attribute = frappe.get_doc({
"doctype": "Item Attribute",
"attribute_name": "_Test_Length",
"numeric_values": 1,
"from_range": 0.0,
"to_range": 100.0,
"increment": 0
})
You could also do this directly through javascript:
}
};
frappe.ui.form.save(me, "cancel", after_cancel, btn);
});
}, on_error);
};
// delete the record
_f.Frm.prototype.savetrash = function() {
this.validate_form_action("Delete");
frappe.model.delete_doc(this.doctype, this.docname, function(r) {
window.history.back();
});
};
_f.Frm.prototype.amend_doc = function() {
if(!this.fields_dict['amended_from']) {
alert('"amended_from" field must be present to do an amendment.');
return;
}
this.validate_form_action("Amend");