chafor
March 30, 2015, 2:29pm
1
Hi,
I’m trying to create a new App for ERP Next call Work Order 2. In the page I’ve create a link with the Customer. Now I’m trying to fetch info from the customer and put it in field call Shipping Address. So base on the Librairy exemple, I create that script :
frappe.ui.form.on("Work Order 2", "Customer",
function(frm) {
frappe.call({
"method": "frappe.client.get",
args: {
doctype: "Customer",
name: frm.doc.customer
},
callback: function (data) {
frappe.model.set_value(frm.doctype,
frm.docname, "shipping_address",
data.message.territory)
}
})
});
For testing purpose I try to put the value of the territory field in shipping_address but it’s not working. Any idea why?
Here the error code I get from Frappe :
Message
Customer Customer not found
Not found
Thank you
chafor
March 30, 2015, 2:33pm
2
Ok I found my error the Name args was customer with a C capital. since it’s named “Customer”.
In the line, “Customer” need to be the name of the field that you have in the doctype. Normally is in lower case. try it and let me know.
chafor
March 30, 2015, 2:43pm
4
thank you geekroot. It was my error :
args: {
doctype: “Customer”,
name: frm.doc.C ustomer
By writing it with a C I correct it, since my field in the doctype is writing Customer.
chafor
March 30, 2015, 2:57pm
5
Ok, now for some more complex stuff. I need to fetch a shipping address from the customer. I should be able to do that by using the customer field and the address_type filed from the Address Doctype.
I suppose I need to change this part of the code :
args: {
doctype: "Customer",
name: frm.doc.customer
}
For the doctype arg : probably “Address” and then should I just add address_type: “Shipping” and customer: frm.doc.Customer so it look like that :
args: {
doctype: "Customer",
address_type: "Shipping"
customer: frm.doc.Customer
}
What do you think?
chafor
March 30, 2015, 3:09pm
6
Hum look like this don’t work :
frappe.ui.form.on("Work Order 2", "Customer",
function(frm) {
frappe.call({
"method": "frappe.client.get",
args: {
doctype: "Address",
customer: frm.doc.Customer,
address_type: "Shipping"
},
callback: function (data) {
frappe.model.set_value(frm.doctype,
frm.docname, "shipping_address",
data.message.address_line1)
}
})
});
Do somebody have a idea?
Thank you
rmehta
March 31, 2015, 12:27pm
7
Call your args with filters
:
args: {
doctype: "Address",
filters: {customer: frm.doc.Customer, address_type:"Shipping"}
}
import frappe.model
import frappe.utils
from frappe import _
from frappe.desk.reportview import validate_args
from frappe.model.db_query import check_parent_permission
from frappe.utils import get_safe_filters
if TYPE_CHECKING:
from frappe.model.document import Document
"""
Handle RESTful requests that are mapped to the `/api/resource` route.
Requests via FrappeClient are also handled here.
"""
@frappe.whitelist()
def get_list(
doctype,
fields=None,