Need to force users to enter amount > 0 in the item rate in sales orders

Hi;

I need to force users to enter amount>0 in the sales order items, how can I do this ??



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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6228ab56-19d7-4a82-a0e1-6e8c73fc205b%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
You can add a client script

cur_frm.cscript.validate = function(doc) {
  if(doc.value <= 0) {
     msgprint("Please enter a value for X");
     throw, "X required";
  }
}



On Wednesday, March 5, 2014 4:09:34 PM UTC+5:30, HF wrote:
Hi;

I need to force users to enter amount>0 in the sales order items, how can I do this ??



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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/31564170-c8e4-40f6-85c4-c6761368b86a%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
How this will affect every line in the sales items ??



On Wednesday, March 5, 2014 12:39:34 PM UTC+2, HF wrote:
Hi;

I need to force users to enter amount>0 in the sales order items, how can I do this ??



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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/5d16f5ba-d095-4cb5-b282-31e06fcf9ded%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
sorry you can try this;

cur_frm.cscript.validate = function(doc) {
  $.each(wn.model.get("Sales Order Item", {parent:doc.name}), function(i, d) {
    if(d.amount <= 0) {
      msgprint("Please enter a value for X for item " + d.item_code);
      throw, "X required";
    }
  }
}

On Sunday, March 9, 2014 5:41:56 PM UTC+5:30, HF wrote:
How this will affect every line in the sales items ??



On Wednesday, March 5, 2014 12:39:34 PM UTC+2, HF wrote:
Hi;

I need to force users to enter amount>0 in the sales order items, how can I do this ??



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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/d808e29b-3715-47f8-a9a5-eac007e128a5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Please check the syntax, it doesn't work !!!



On Monday, March 10, 2014 8:55:52 AM UTC+2, rushabh wrote:
sorry you can try this;

cur_frm.cscript.validate = function(doc) {
  $.each(wn.model.get("Sales Order Item", {parent:doc.name}), function(i, d) {
    if(d.amount <= 0) {
      msgprint("Please enter a value for X for item " + d.item_code);
      throw, "X required";
    }
  }
}

On Sunday, March 9, 2014 5:41:56 PM UTC+5:30, HF wrote:
How this will affect every line in the sales items ??



On Wednesday, March 5, 2014 12:39:34 PM UTC+2, HF wrote:
Hi;

I need to force users to enter amount>0 in the sales order items, how can I do this ??



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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/a7340929-1244-488b-a6d9-249488ffa579%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
cur_frm.cscript.validate = function(doc) {
  $.each(wn.model.get("Sales Order Item", {parent:doc.name}), function(i, d) {
    if(d.amount <= 0) {
      msgprint("Please enter a value for X for item " + d.item_code);
      throw, "X required";
    }
  })
}

On 10-Mar-2014, at 2:35 pm, HF <gm...@gmail.com> wrote:

Please check the syntax, it doesn't work !!!



On Monday, March 10, 2014 8:55:52 AM UTC+2, rushabh wrote:
sorry you can try this;

cur_frm.cscript.validate = function(doc) {
  $.each(wn.model.get("Sales Order Item", {parent:doc.name}), function(i, d) {
    if(d.amount <= 0) {
      msgprint("Please enter a value for X for item " + d.item_code);
      throw, "X required";
    }
  }
}

On Sunday, March 9, 2014 5:41:56 PM UTC+5:30, HF wrote:
How this will affect every line in the sales items ??



On Wednesday, March 5, 2014 12:39:34 PM UTC+2, HF wrote:
Hi;

I need to force users to enter amount>0 in the sales order items, how can I do this ??




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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/a7340929-1244-488b-a6d9-249488ffa579%40googlegroups.com.

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



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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/FE2F3FA6-DAAA-40E1-AF80-00C9CC454A9D%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.
Hi Nabin;

It is not working ??




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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/b4c5c954-64ca-42e9-b84c-e9a1e9c832d7%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Try this: http://pastebin.com/bxkZTDiP


On Mon, Mar 10, 2014 at 6:27 PM, HF <gm...@gmail.com> wrote:
Hi Nabin;

It is not working ??




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.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/b4c5c954-64ca-42e9-b84c-e9a1e9c832d7%40googlegroups.com.

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



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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CAAQzbF03zrPh4gNsNAqx7koSkQxebCYf1bCbVrE5_89if-8jNA%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.
It doen't work;

I think i and d variables are not defined for the function to work properly !!




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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/fb75fcf5-d383-4a33-a00a-e866487fd4e1%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Hi;

I found the correct solution as the below code, it works fine.

cur_frm.cscript.custom_validate = function(doc) {
    var cl = getchildren(cur_frm.cscript.tname, doc.name, cur_frm.cscript.fname);
for(var i = 0; i<cl.length; i++){
amt = flt(cl[i].amount);
      if(amt==0) {
        msgprint("Zero Value not allowed in any line of Sales Order, Please correct.");
        return false;
        }
}
}




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.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/acf9a3dc-6b0d-466d-951c-786b9540243a%40googlegroups.com.

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