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?
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?
@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.
@Gitika_parashar There is a workaround to achieve this. As follows;
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.)
In the Sales Order add add a custom link field called warehouse also, and make it read only.
Go to Custom Script and create a new script for Sales Order as follows;
use this script to fetch the warehouse when choosing customer cur_frm.add_fetch("customer", "warehouse", "warehouse");
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') });
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.
In the Sales Order add a custom link field called warehouse also, and make it read only.
Go to Custom Script and create a new script for Sales Order as follows;
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.
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?
@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.
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:
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.
If I understand correctly you need the following for the 1st situation “Choose branch at sales order/invoice”
Create a field in the sales order or sales invoice and call it doc_locationtype is link and option is the link to the doctype
and another field which is read only and call it delivery_warehousetype 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)
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”
Create a field in the User customize form and call it doc_locationtype is link and option is the link to the doctype
and another field which is read only and call it delivery_warehousetype is data and option is doc_location.delivery_warehouse
Create a field in the Sales Order customize form and call it delivery_warehousetype is data and option is user.delivery_warehouse
and another field which is read only and call it usertype 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)
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
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 ?
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); }