ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

Can I set default warehouse for a customer?


#21

If you add a field that is called “delivery_warehouse” , then you should change the script accordingly, like this.

cur_frm.add_fetch(“customer”, “delivery_warehouse”, “delivery_warehouse”);

frappe.ui.form.on(“Sales Order”, “customer”, function(frm) {
frappe.model.with_doc(“Company”, frm.doc.company, function() {
var w = frappe.model.get_doc(“Company”, frm.doc.company);
frm.set_value(“delivery_warehouse”, w.delivery_warehouse);
});
});


#22

Hi @mrmo,

Thanks for your respond. But after changing custom script, it shows following custom script error in Sales Order:

SyntaxError: Invalid or unexpected token
at Class.setup (http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:2692:18)
at _f.Frm.setup (http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:172:22)
at _f.Frm.refresh (http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:446:9)
at Class.load (http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:87:33)
at http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:82:7
at Object.with_doc (http://192.168.3.183/assets/js/desk.min.js?ver=1540292152.54:5516:4)
at Class.show_doc (http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:65:16)
at http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:24:8
at Object.with_doctype (http://192.168.3.183/assets/js/desk.min.js?ver=1540292152.54:5455:17)
at Class.make (http://192.168.3.183/assets/js/form.min.js?ver=1540292152.54:20:17)

Thanks,


#23

Can you please send screenshots of the customize form where you added the fields.


#24

Hi @mrmo,

Here are the screenshots where the fields added:

  1. Sales Order

  2. Customer

  3. Company

Thanks,


#25

Can you please explain the steps you want to take. At this moment you have the Delivery Warehouse in Company master and Customer master.
What is the level of importance?
Do you want to fetch from Company - > Customer -> Sales Order or Company - > Sales Order?
Thanks


#26

Hi @mrmo,

Since i have multiple warehouse in just one company, my main purpose is to fetch Delivery Warehouse to Sales Order item level, so that user don’t need change it in every items in Sales Order.

Thanks,


#27

If you lock the warehouse with the customer then do the following;

cur_frm.add_fetch(“customer”, “delivery_warehouse”, “delivery_warehouse”);
frappe.ui.form.on("Sales Order","validate", function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[i].warehouse = cur_frm.doc.delivery_warehouse
}
cur_frm.refresh_field('items')
});

This script will copy the delivery_warehouse field into all rows when you click save in the sales order
Actually you do not need to put it in your company master at all, it is useless, because the default warehouse can be set in Stock Settings for that purpose.


#28

Hi @mrmo,

It works now. Thanks so much for your replies.

Have a good day.
Sopheak :grinning:


#29

hello,
I have near about same problem in which i want warehouse from user to sales order.
so that when that particular customer logs in warehouse will be fetched from the user section where i have created one custom field “warehouse” of link type into the sales order item "delivery warehouse " field which is also of link type as in 2nd screen shot

I have followed your all steps but is not working with following script i have added script in “Sales Order”

 cur_frm.add_fetch(“user”, “warehouse”, “warehouse”);

 frappe.ui.form.on("Sales Order Item","validate", function(){
 for (var i =0; i < cur_frm.doc.items.length; i++){
 cur_frm.doc.items[i].warehouse = cur_frm.doc.warehouse
 }
 cur_frm.refresh_field('items')
});

1)In the item of Sales order

  1. In user "warehouse " custom field

since it is not fetching from user please suggest the changes in script pr any more customization


#30

You should use on Sales Order not Sales Order Item to trigger the script. like this.

cur_frm.add_fetch(“user”, “warehouse”, “warehouse”);

 frappe.ui.form.on("Sales Order","validate", function(){
 for (var i =0; i < cur_frm.doc.items.length; i++){
 cur_frm.doc.items[i].warehouse = cur_frm.doc.warehouse
 }
 cur_frm.refresh_field('items')
});

Greetings


#31

thank you @mrmo
I have applied the suggestion but not working there is error in script.

to be fetch from
custom field named “warehouse” in “user” doctype.
into
“warehouse”(not custom field) in items of sales order referenced from sales order item.


#32

You have to create a custom field “warehouse” (read only) in Sales Order also, to fetch the field from user first.
copy my script below, because yours has wrong quotes.

cur_frm.add_fetch("user", "warehouse", "warehouse");

then use this script to put the warehouse field from parent to child

cur_frm.add_fetch("user", "warehouse", "warehouse");

 frappe.ui.form.on("Sales Order","validate", function(){
 for (var i =0; i < cur_frm.doc.items.length; i++){
 cur_frm.doc.items[i].warehouse = cur_frm.doc.warehouse
 }
 cur_frm.refresh_field('items')
});

#33

thank you @mrmo
I have created the custom link field “warehouse” read only in sales order
and used the above script as it is but still its not working

*this is in User

*In child of Sales order it has by default value


#34

Send me a PM with temporary credentials, I will take a look for you.


#35

@mrmo, you sound very familiar with Custom Scripts. I’ve been looking for ways for scripting the action of taking a list of Purchase Invoice Items and making a Product Bundle with them. Do you know what JS objects I need to get the Items and make a Product Bundle object? I literally can’t find any documentations what APIs are available to me in Custom Scripts and that’s been a very, very frustrating experience.


#36

Please don’t @ tag your requests, and do start a new thread thanks


#37

I wouldn’t resort to tagging on unrelated posts if my threads received any replies.


#38

Please appreciate and respect this is a volunteer forum ok?


#39
  1. Create a custom field purchase_invoice in Product Bundle with Link to Purchase Invoice
  2. Put below script in your Custom script for DocType Product Bundle.
frappe.ui.form.on("Product Bundle", "purchase_invoice", function(frm) {
if(frm.doc.purchase_invoice)
frappe.model.with_doc("Purchase Invoice", frm.doc.purchase_invoice, function() {
var pi = frappe.model.get_doc("Purchase Invoice", frm.doc.purchase_invoice)
cur_frm.clear_table("items");
$.each(pi.items, function(index, row){
d = frm.add_child("items");
d.item_code = row.item_code;
d.qty = row.qty;
d.description = row.description;
cur_frm.refresh_field("items");
})
});
});
  1. What happens is, that when you input the Purchase Invoice ID into that field it will fetch all items in the items child table and put them in your Product Bundle Child Table.

#40

Your way is fine, but using your script as reference, I’m attempting to make a script to create new Product Bundle when I submit the Purchase Invoice because it’ll be an undue burden on my target users.

Besides that, my Googling informed be cur_frm has been deprecated, are you sure it will work? I’m on v11.