Hi! My intention is to execute several actions and create docs from a filled custom doc.
Here is my code:
frappe.ui.form.on("Compra de leite Lote", "on_submit", function(frm) {
let docs = []
$.each(frm.doc.tabela_dados || [], function(i, v) {
docs.push({
doctype: "Purchase Receipt",
set_posting_time: 1,
posting_date: frm.doc.posting_date,
posting_time: frm.doc.posting_time,
supplier: v.produtor,
items: {
item_code: (v.qualidade == "Bom" ? "Leche Bueno" : "Leche Acido"),
qty: v.qtde,
rate: (v.qualidade == "Bom" ? frm.doc.preco_compra : frm.doc.preço_acido),
warehouse: "Leite comprado do produtor"
}
})
})
const funcs = docs.map((doc) => {
frappe.call({
method: "frappe.client.insert",
args: {
doc: doc // doc object
},
callback: function(r) {}
})
})
Promise.all(funcs).then(() => {
console.log("Done");
})
})
It raises an exception at “items” table.
This is the final lines of the exception:
File "/home/oficina1/erpnext-10.1.42-0/apps/erpnext/htdocs/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 40, in validate
self.set_missing_values(for_validate=True)
File "/home/oficina1/erpnext-10.1.42-0/apps/erpnext/htdocs/frappe-bench/apps/erpnext/erpnext/controllers/buying_controller.py", line 70, in set_missing_values
self.set_missing_item_details(for_validate)
File "/home/oficina1/erpnext-10.1.42-0/apps/erpnext/htdocs/frappe-bench/apps/erpnext/erpnext/controllers/accounts_controller.py", line 191, in set_missing_item_details
if item.get("item_code"):
AttributeError: 'unicode' object has no attribute 'get'
I’m kind of newbie on this… I presume i’m doing something wrong to insert rows on my doc, no?
Thanks in advance!