Try ERPNext Buy Support Partners Foundation

Supplier Address

I created two custom fields in the “Stock Entry” doc - address_title which is a Link with Address as the options. And another custom field address_detail which is small text.

Then I used the following custom script:

frappe.ui.form.on("Stock Entry", "address_title", function(frm, cdt, cdn) {
        return frm.call({
            method: "erpnext.utilities.doctype.address.address.get_address_display",
            child: d,
            args: {
                "address_dict": frm.doc.address_title
            },
                        callback: function(r) {
            if(r.message)
                                frappe.model.set_value("detail_address", r.message);
        }
        });
});

But the detail_address field is not getting populated with the address.What am I doing wrong? I already have a custom script for “Stock Entry” document. The total stock entry custom script therefore looks like this:

var calculate_total_item_weight = function(frm, cdt, cdn) {
    var d = locals[cdt][cdn];
    if (d.qty && d.net_weight) {
        d.total_item_weight = flt(d.qty) * flt(d.net_weight);
        refresh_field('total_item_weight');
    }
    
    calculate_total_weight(frm);
}

var calculate_total_weight = function(frm) {
    var total_weight = frappe.utils.sum(
        (frm.doc.items || []).map(function(i) { return i.total_item_weight; })
    );
    
    frm.set_value("total_weight", total_weight);
}

frappe.ui.form.on("Stock Entry Detail", "qty", function(frm, cdt, cdn) {
    calculate_total_item_weight(frm, cdt, cdn);
})

frappe.ui.form.on("Stock Entry Detail", "net_weight", function(frm, cdt, cdn) {
    calculate_total_item_weight(frm, cdt, cdn);
})
frappe.ui.form.on("Stock Entry", "address_title", function(frm, cdt, cdn) {
        return frm.call({
            method: "erpnext.utilities.doctype.address.address.get_address_display",
            child: d,
            args: {
                "address_dict": frm.doc.address_title
            },
                        callback: function(r) {
            if(r.message)
                                frappe.model.set_value("detail_address", r.message);
        }
        });
});

Try the following:

frappe.ui.form.on("Stock Entry", "address_title", function(frm, cdt, cdn) {
	return frappe.call({
		method: "erpnext.utilities.doctype.address.address.get_address_display",
		args: {
			"address_dict": frm.doc.address_title
		},
		callback: function(r) {
			if(r.message)
				frm.set_value("detail_address", r.message);
		}
	});
});
1 Like

Works wonderfully well.

Thanks for your help.

Jay

1 Like

This does not work any more.

I understand the information should be pulled out now by using
frappe.db.get_value something like what is described here

Can you please help a bit there.

Regards
PK

doesn’t work for me…it showing “ModuleNotFoundError: No module named ‘erpnext.utilities.doctype.address’”