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

Can I set default warehouse for a customer?


#1

Hi,

Is it possible to select a default warehouse for a particular customer so that I do not have to enter it again with each item in case default warehouse for that particular item is different.

To make it more clear I want to supply to a particular customer only from a particular warehouse. So as I enter my sales order, is it possible that as soon as I select my customer, warehouse for each ordered item automatically selects to the warehouse associated with that customer?

Regards


#2

I don’t think this feature exists out of the box.


#3

Is this functionality there is the system now?

If I have a warehouse for each city and then when I am creating sales order for a customer in particular city, it should pickup that city’s warehouse. How do I achieve this?


#4

@Gitika_parashar: you will have to undertake a custom software development effort to extend ERP Next capabilities per your scenario described. This is not available out of the box.


#5

@Gitika_parashar There is a workaround to achieve this. As follows;

  1. In Customer Doctype add a custom link field called warehouse and when adding a new customer choose the warehouse you want to link the customer with.
    (Or if you want to fetch it together with territory then add the custom field in territory doctype and do the add_fetch in customer custom script.)

  2. In the Sales Order add add a custom link field called warehouse also, and make it read only.

  3. Go to Custom Script and create a new script for Sales Order as follows;

  4. use this script to fetch the warehouse when choosing customer
    cur_frm.add_fetch("customer", "warehouse", "warehouse");

  5. And use this script to insert the linked warehouse in the warehouse field in the child fields on validate.
    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') });

And that should do it.


Set warehouse automatically based on company
Website list view in stock
#6

hi mrmo

i tried the solution offered by you, it works.

can you please tell me how to link it with customer`s address.

i have a customer with different branches, so i want the warehouse to be selected according to the address ??


#7

@tanuj82685

  1. In Address Doctype add a custom link field called warehouse and when adding a new address for the customer choose the warehouse you want to link the customer with.
  2. In the Sales Order add a custom link field called warehouse also, and make it read only.
  3. Go to Custom Script and create a new script for Sales Order as follows;
  4. use this script to fetch the warehouse when choosing customer.
    If you set warehouse in billing address than use this cur_frm.add_fetch("customer_address", "warehouse", "warehouse");
    If you set warehouse in shipping address than use this cur_frm.add_fetch("shipping_address_name", "warehouse", "warehouse");

The rest stays the same, and in sales order just choose the address you want to send to every time, if I were you I would set the standard warehouse in the customer also, so when the standard shipping address gets fetched you at least are sure there is a standard warehouse connected to the customer. The reason is add_fetch function works only when you actually do something on the link field.


#8

I want to set default company for each user. Can do that by link field called company in customer and then custom script to fetch default company.
Now I would like to set default warehouse in items for the company. I have custom field in company for delivery warehouse.
How can I fetch default warehouse based on the company selected?


#9

Just create User Permission Role for that User to define default Company.


#10

@umair apologies, I meant company for each customer.
Basically I want to define default delivery warehouse company wise.
And Default company for every customer.
So delivery warehouse per item is selected automatically.


#11

@rijul Do you want to set the warehouse per item row or per invoice/order? Please state clearly.


#12

Per order. The reason for doing all this is so that I don’t have to type-in manually, delivery warehouse for each item in the table.

As of now I have created custom link field warehouse in sales order.
Adding into sales order custom script-

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’)
});

But this does not update warehouse in item table


#13

In your company add custom field warehouse and in customer add custom field company.
When you create a customer choose the company you want and in your order document add the following custom script:

cur_frm.add_fetch("customer", "warehouse", "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("warehouse", w.warehouse); }); });

let me know if it works.


#14

Possible to advise the script that I want to change delivery warehouse automatically when I select the naming series at sales order ?


#15

If you would like to change it to name you already know use this script

frappe.ui.form.on(“Sales Order”,“naming_series”, function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[i].warehouse = "Test Warehouse - TST"
}
cur_frm.refresh_field(‘items’)
});

If you would like to change it to field in the parent doc use this one

frappe.ui.form.on(“Sales Order”,“naming_series”, function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[i].warehouse = cur_frm.doc.your_field
}
cur_frm.refresh_field(‘items’)
});

If you would like to change it to field in the same child table use this one

frappe.ui.form.on(“Sales Order”,“naming_series”, function(){
for (var i =0; i < cur_frm.doc.items.length; i++){
cur_frm.doc.items[i].warehouse =   cur_frm.doc.items[i].your_field
}
cur_frm.refresh_field(‘items’)
});

#16

Hi Thanks.

I’ve created a DOCTYPE=DOC_LOCATION.
Which have the fields as : branch_code, branch_name, delivery_warehouse, company, d_sales_invoice_s, and d_sales_order_s

When I choose Branch Code or Branch Name at Either Sales Order or Sales Invoice, I’d like to update the Delivery Warehouse automatically.

and also, maybe the login use default Branch Code.

Branch Name I link with the Branch at Employee.

Would appreciate if you could advise further.

Thanks.


#17

If I understand correctly you need the following for the 1st situation “Choose branch at sales order/invoice”

  1. Create a field in the sales order or sales invoice and call it
    doc_location type is link and option is the link to the doctype
    and another field which is read only and call it
    delivery_warehouse type is data and option is doc_location.delivery_warehouse

next put this in your custom script depending on your doctype (i chose Sales Order as an example)

  1.    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’)
         });
    

for the 2nd situation “Choose branch based on user”

  1. Create a field in the User customize form and call it
    doc_location type is link and option is the link to the doctype
    and another field which is read only and call it
    delivery_warehouse type is data and option is doc_location.delivery_warehouse
  2. Create a field in the Sales Order customize form and call it
    delivery_warehouse type is data and option is user.delivery_warehouse
    and another field which is read only and call it
    user type is link and option is User and default is user

next put this in your custom script depending on your doctype (i chose Sales Order as an example)

  1.    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’)
         });
    

and that is it, this way the warehouse will be fetched either way through the link to the doctype you choose in the sales order or invoice if you choose scenario 1 or it will be fetched from the user which happens automatically when the current user creates a new sales order or invoice. when you click save in the either doctype the system will use the custom script to put the value of the delivery_warehouse in all rows that are created during the transaction. good luck


#18

Yes, this way works perfect.
Another question, for the Sales Invoice, I need to prevent the Branch ( Delivery Warehouse ) Being change if the document is being amended or created from Sales Order. I used the following script, its work to set the Branch become read only,

but when I click and unclick the “Include Payment (POS)” , the field become visible again. any idea ?

frappe.ui.form.on(“Sales Invoice”, “onload”, function(frm) {

if(cur_frm.doc.amended_from.length > 0)
{
cur_frm.set_df_property(“iverp_doc_location”, “read_only”,true);
cur_frm.refresh_field(‘iverp_doc_location’)

}

});


#19

Sorry for the late reply. I have missed your request.
You can use this script to make the field read only after saving or refresh.

frappe.ui.form.on("MyDocType", "refresh", function(frm) { // use the __islocal value of doc, to check if the doc is saved or not frm.set_df_property("myfield", "read_only", frm.doc.__islocal ? 0 : 1); }

Source: https://erpnext.org/docs/user/manual/en/customize-erpnext/custom-scripts/custom-script-examples/make-read-only-after-saving


#20

Hi @mrmo,

I have situation same as @rijul where I have only one company but multiple warehouse.

I have followed all the steps you mentioned:

  1. Add custom field in Company as “delivery_warehouse”
  2. Add custom field in Customer as “Company” & “delivery_warehouse”
  3. Add custom field in Sales Order as “delivery_warehouse”
  4. Add below script to Custom Scrip for Sales Order:

cur_frm.add_fetch(“customer”, “warehouse”, “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(“warehouse”, w.warehouse); }); });

But the warehouse is still not push through to sales order item. Any steps i’m missing?

Thanks,
Sopheak