Client Script to Check Delivery Note Details

Hi. I'd like to ask for help on how to create a custom script that will check for the contents of field against_sales_order in each row of the Delivery Note Item table and evaluate if it is empty (null) or not.  If the against_sales_order is null, then the form should not be saved or submitted (validated = false;).

I am aware that there is a "Sales Order Required" toggle in Selling Settings, which we can set to "Yes" and is what we currently do.  However, I want to change this toggle to "No" because there are specific use-cases where an invoice can be done by certain roles/users without a sales order. Importantly, these use cases will also not impact inventory. Thus, I intend to set a permission check via client script on the "update_stock" field that it must always be unchecked (or just hide it and default it as unchecked).

By setting "Sales Order Required" to "No", a user can now create transactions that impact inventory without a sales order.  This is not ideal as we use submitted Sales Orders as a sort of approval form to trigger stock delivery.  We do not want to be creating Delivery Notes without a proper order.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Laurence, please see the section "Calculate Incentive in Sales Team table based on some custom logic" of https://github.com/webnotes/wnframework/wiki/Client-side-scripting

This should give you a path.



2013/11/29 lxnow <la…@union.ph>

Hi. I'd like to ask for help on how to create a custom script that will check for the contents of field against_sales_order in each row of the Delivery Note Item table and evaluate if it is empty (null) or not. If the against_sales_order is null, then the form should not be saved or submitted (validated = false;).


I am aware that there is a "Sales Order Required" toggle in Selling Settings, which we can set to "Yes" and is what we currently do. However, I want to change this toggle to "No" because there are specific use-cases where an invoice can be done by certain roles/users without a sales order. Importantly, these use cases will also not impact inventory. Thus, I intend to set a permission check via client script on the "update_stock" field that it must always be unchecked (or just hide it and default it as unchecked).


By setting "Sales Order Required" to "No", a user can now create transactions that impact inventory without a sales order. This is not ideal as we use submitted Sales Orders as a sort of approval form to trigger stock delivery. We do not want to be creating Delivery Notes without a proper order.



Note:



If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.



    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.




--

Maxwell Morais
Tecnologia da Informação
+55 11 3931-1412 Ramal 31

www.realizemodulados.com.br



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Laurence,

From what I understand, Sales Order to be mandatory for certain set of users and not for other users?

here is what you can write:

https://gist.github.com/rmehta/7751058

- Rushabh

On Friday, November 29, 2013 3:52:23 PM UTC+5:30, lxnow wrote:
Hi. I'd like to ask for help on how to create a custom script that will check for the contents of field against_sales_order in each row of the Delivery Note Item table and evaluate if it is empty (null) or not.  If the against_sales_order is null, then the form should not be saved or submitted (validated = false;).

I am aware that there is a "Sales Order Required" toggle in Selling Settings, which we can set to "Yes" and is what we currently do.  However, I want to change this toggle to "No" because there are specific use-cases where an invoice can be done by certain roles/users without a sales order. Importantly, these use cases will also not impact inventory. Thus, I intend to set a permission check via client script on the "update_stock" field that it must always be unchecked (or just hide it and default it as unchecked).

By setting "Sales Order Required" to "No", a user can now create transactions that impact inventory without a sales order.  This is not ideal as we use submitted Sales Orders as a sort of approval form to trigger stock delivery.  We do not want to be creating Delivery Notes without a proper order.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Thanks guys. This is the final code I used:

cur_frm.cscript.custom_validate = function(doc) {

// Do not allow DN without SO (if we untick SO required option in Selling Settings)

  var items = wn.model.get("Delivery Note Item", {parent: doc.name})
  var items_against_sales_order = $.map(items, function(d) { return d.against_sales_order ? d : null })
 
  if(items.length > items_against_sales_order.length) {
 msgprint("Please make against sales order");
  validated = false;
  }

}

On Monday, December 2, 2013 11:21:30 PM UTC+8, rushabh wrote:
Laurence,

From what I understand, Sales Order to be mandatory for certain set of users and not for other users?

here is what you can write:


- Rushabh

On Friday, November 29, 2013 3:52:23 PM UTC+5:30, lxnow wrote:
Hi. I'd like to ask for help on how to create a custom script that will check for the contents of field against_sales_order in each row of the Delivery Note Item table and evaluate if it is empty (null) or not.  If the against_sales_order is null, then the form should not be saved or submitted (validated = false;).

I am aware that there is a "Sales Order Required" toggle in Selling Settings, which we can set to "Yes" and is what we currently do.  However, I want to change this toggle to "No" because there are specific use-cases where an invoice can be done by certain roles/users without a sales order. Importantly, these use cases will also not impact inventory. Thus, I intend to set a permission check via client script on the "update_stock" field that it must always be unchecked (or just hide it and default it as unchecked).

By setting "Sales Order Required" to "No", a user can now create transactions that impact inventory without a sales order.  This is not ideal as we use submitted Sales Orders as a sort of approval form to trigger stock delivery.  We do not want to be creating Delivery Notes without a proper order.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.