I need to get a default value in field on table depends on Branch
For example: in sales order i need when i choose Branch = x
to get warehouse = A100 in Sales order Item table by default
also when i choose Branch x in Sales invoice to get a specific cost center for the income account
thanks in advance
Hi,
First you need to create new field as ‘warehouse’ in “Branch” master for that,
i.Go to ‘Custom field’ form
ii. Go to “Branch” master ,you can see “Warehouse” field .fill data in that and save.
2.In sales order item you need to add field i.e Branch and Warehouse
for that -
i.Go to Doctype, Search for- ‘Sales Order Item’ and Add field ,Update
Do same for cost center.
rohit_w
December 28, 2016, 11:40am
3
Hi @Hanigameel888
Try using custom script
frappe.ui.form.on('Sales Order', {
branch: function(frm) {
if(frm.doc.branch == 'X') {
$.each(frm.doc.items, function(index, row){
frappe.model.set_value(row.doctype, row.name, "warehouse", "A100");
})
}
}
})
I hope branch field is available on the sales order form
but i want the warehouse i linked to branch in branch master to be the default warehouse in filed “warehouse” in sales order item table not in new field “b warehouse”
thanks for help
hi rohit_w
thank you it works but only in first row in the table the rest items gets the default warehouse from item master>
how to get it work for all items in Sales order item table
thanks in advance
frappe.ui.form.on(‘Sales Order’, {
branch: function(frm) {
if(frm.doc.branch == ‘Baron’) {
$.each(frm.doc.items, function(index, row){
frappe.model.set_value(row.doctype, row.name, “warehouse”, “A1200 - A”);
})
}
}
})
rohit_w
December 28, 2016, 1:13pm
8
Hi @Hanigameel888
ok
Add below code as well, items_add event trigger when user click on add new row
frappe.ui.form.on('Sales Order Item', {
items_add: function(frm, cdt, cdn) {
if(frm.doc.branch == 'Baron') {
frappe.model.set_value(cdt, cdn, "warehouse", "A1200 - A");
}
}
})
it works only when i add new row like you said but the first line not working
rohit_w
December 29, 2016, 5:14am
10
Hi @Hanigameel888 ,
keep the both code
frappe.ui.form.on('Sales Order', {
branch: function(frm) {
if(frm.doc.branch == 'Baron') {
$.each(frm.doc.items, function(index, row){
frappe.model.set_value(row.doctype, row.name, "warehouse", "A1200 - A");
})
}
}
})
frappe.ui.form.on('Sales Order Item', {
items_add: function(frm, cdt, cdn) {
if(frm.doc.branch == 'Baron') {
frappe.model.set_value(cdt, cdn, "warehouse", "A1200 - A");
}
}
})
Can you help me the same case but in Sales Invoice Form
when i choose Branch = Baron, get Cost Center for Income account= Baron in SAles Invoice Item Table