Get values of table fields

Im getting values of Purchase Invoice form, but i need get two values of my custom child table too.
The doctype of table it’s named by ‘Parcelas’, the columns are ‘Vencimento’(date) and ‘Valor’(currency).

My call js code:
frappe.call({
method: “erpnext.accounts.utils.make_titulo”,
args:{
due_date: frm.doc.due_date,
bill_no: frm.doc.bill_no,
posting_date: frm.doc.posting_date,
supplier_name: frm.doc.supplier_name,
company: frm.doc.company,
},

Have you tried:

frm.doc.parcelas.vencimento
frm.doc.parcelas.valor

Also, can you show all your code? Where is that section of code being run?

Already tried, parcelas it’s an another object

My code:
PY:

@frappe.whitelist()
def make_titulo(due_date, bill_no, posting_date, supplier_name, company):
        titulos = frappe.new_doc("Titulos")
        titulos.naming_series = "TIT-A-PAGAR-"
        titulos.tipo_de_parte = "Supplier"
        titulos.tipo_documento = "Purchase Invoice"
        titulos.data_vencimento = due_date
        titulos.bill_no = bill_no
        titulos.data_postagem = posting_date
        titulos.parte = supplier_name
        titulos.empresa = company
        titulos.save()
        return titulos.data_vencimento, titulos.bill_no, titulos.data_postagem, titulos.parte, titulos.empresa

JS:

frappe.ui.form.on("Purchase Invoice", "validate", function(frm) {
    $.each(frm.doc.parcelas || [], function(i, d) {
        // Create titulo
        frappe.call({
            method: "erpnext.accounts.utils.make_titulo",
            args:{
                    due_date: frm.doc.due_date,
                    bill_no: frm.doc.bill_no,
                    posting_date: frm.doc.posting_date,
                    supplier_name: frm.doc.supplier_name,
                    company: frm.doc.company,
             },
            callback: function(r)
            {console.log(r)}
        });
    });
});

Im working with installments, the Parcelas table represent the installments, each line is a installment.
So, for each line of the table, create a new Titulo document, but i need get the values of the table too: vencimento(date) and valor(value of installment)

Installments of some Purchase Invoice

The ‘Titulos’ generated after save the Purchase Invoice

You should just be able to use “d”, given that you’re looping over that.

d.valor

When i do console.log(frm.doc.parcelas):

0:Object
creation:""
data_vencimento:“2017-07-05”
docstatus:0
doctype:“Parcelas”
idx:1
modified:""
modified_by:“Administrator”
name:“Novo Parcelas 1”
owner:“Administrator”
parent:“Novo Nota Fiscal de Compra 1”
parentfield:“parcelas”
parenttype:“Purchase Invoice”
valor:10

The script it’s working fine, i just wanna know how can i get the values of the child table
For now, im getting the value just of Purchase Invoice form…

Yeah, but i’ll need change all of my python script right?

I tried ‘self.valor’ in python, but im having problem with args… The log is saying it’s missing 1 args.
I writed doc: ‘cur_frm.doc’ in my javascript args, but doesn’t works…

Try this:

@frappe.whitelist()
def make_titulo(due_date, bill_no, posting_date, supplier_name, company, vencimento, valor):
        titulos = frappe.new_doc("Titulos")
        titulos.naming_series = "TIT-A-PAGAR-"
        titulos.tipo_de_parte = "Supplier"
        titulos.tipo_documento = "Purchase Invoice"
        titulos.data_vencimento = due_date
        titulos.vencimento = vencimento
        titulos.valor = valor
        titulos.bill_no = bill_no
        titulos.data_postagem = posting_date
        titulos.parte = supplier_name
        titulos.empresa = company
        titulos.save()
        return titulos.data_vencimento, titulos.bill_no, titulos.data_postagem, titulos.parte, titulos.empresa, titulos.valor, titulos.vencimento

JS:

frappe.ui.form.on("Purchase Invoice", "validate", function(frm) {
    $.each(frm.doc.parcelas || [], function(i, d) {
        // Create titulo
        frappe.call({
            method: "erpnext.accounts.utils.make_titulo",
            args:{
                    due_date: frm.doc.due_date,
                    bill_no: frm.doc.bill_no,
                    posting_date: frm.doc.posting_date,
                    supplier_name: frm.doc.supplier_name,
                    company: frm.doc.company,
                    valor: d.valor,
                    vencimento: d.vencimento,
             },
            callback: function(r)
            {console.log(r)}
        });
    });
});

Ok but, what’s “d”?

File "/home/frappe/frappe-bench/apps/erpnext/erpnext/accounts/utils.py", line 755, in make_titulo
    titulos.valor_total = d.valor
NameError: global name 'd' is not defined

That’s not the code I suggested. Read your own code. You declared d here:

Let me try again

HOOOOOLLY, that worked for me!
Thanks Ben :smile:

1 Like

Now, how can i get the format date?
I wanna get dd/mm/yyyy but, I’m getting the format of database