Need to add a custom field with calculations

How can I add a custom field to the sales order item document that can hold a mathematical equation of another fields ?


ex.:  custom field 1 = fld1  and custom field 2 = fld2  and custom field 3 = fld3     I need the fld3 to hold this value   ==  fld1*fld2/1000  just after entering the values in fld1 and fld2

is that possible?  How ?



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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OZD91z8Qy9YJ.

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

 

 

Dear HF,

You can do that via Document --> New --> Custom Script.

In custom script try the following:

Script Type: Server

Script:

def custom_validate(self):
from webnotes.utils import flt

self.doc.custom_field3 = flt(self.doc.custom_field1)*flt(self.doc.custom_field2)/1000



On Wed, Oct 10, 2012 at 2:28 PM, HF <h…@gmail.com> wrote:
How can I add a custom field to the sales order item document that can hold a mathematical equation of another fields ?

ex.: custom field 1 = fld1 and custom field 2 = fld2 and custom field 3 = fld3 I need the fld3 to hold this value == fld1*fld2/1000 just after entering the values in fld1 and fld2

is that possible? How ?



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

To post to this group, send email to er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OZD91z8Qy9YJ.

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









Regards,
Nabin Hait



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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

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

 

 

Dear HF,

If you want instant calculation on entering the value of field1 and field2, the try the following:

Script Type: Client

Script:

cur_frm.cscript.custom_field1 = function(doc, cdt, cdn) {

if (doc.custom_field1 && doc.custom_field2) {
doc.custom_field3 = doc.custom_field1*doc.custom_field2/1000;
refresh_field(‘custom_field3’);
}
}

cur_frm.cscript.custom_field2 = cur_frm.cscript.custom_field1;




On Wed, Oct 10, 2012 at 2:51 PM, Nabin Hait <na…@gmail.com> wrote:

Dear HF,

You can do that via Document --> New --> Custom Script.

In custom script try the following:

Script Type: Server

Script:

def custom_validate(self):
from webnotes.utils import flt

self.doc.custom_field3 = flt(self.doc.custom_field1)*flt(self.doc.custom_field2)/1000





On Wed, Oct 10, 2012 at 2:28 PM, HF <h…@gmail.com> wrote:
How can I add a custom field to the sales order item document that can hold a mathematical equation of another fields ?


ex.: custom field 1 = fld1 and custom field 2 = fld2 and custom field 3 = fld3 I need the fld3 to hold this value == fld1*fld2/1000 just after entering the values in fld1 and fld2

is that possible? How ?



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

To post to this group, send email to er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OZD91z8Qy9YJ.

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









Regards,
Nabin Hait






Regards,
Nabin Hait



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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

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

 

 

Slight modification in client side code:

cur_frm.cscript.custom_field1 = function(doc, cdt, cdn) {
doc.custom_field3 = flt(doc.custom_field1)*flt(doc.custom_field2)/1000;
refresh_field(‘custom_field3’);

}
cur_frm.cscript.custom_field2 = cur_frm.cscript.custom_field1;


On Wed, Oct 10, 2012 at 3:00 PM, Nabin Hait <na…@gmail.com> wrote:
Dear HF,

If you want instant calculation on entering the value of field1 and field2, the try the following:

Script Type: Client

Script:

cur_frm.cscript.custom_field1 = function(doc, cdt, cdn) {
if (doc.custom_field1 && doc.custom_field2) {
doc.custom_field3 = doc.custom_field1*doc.custom_field2/1000;
refresh_field('custom_field3');
}
}

cur_frm.cscript.custom_field2 = cur_frm.cscript.custom_field1;




On Wed, Oct 10, 2012 at 2:51 PM, Nabin Hait <na...@gmail.com> wrote:

Dear HF,

You can do that via Document --> New --> Custom Script.

In custom script try the following:

Script Type: Server

Script:

def custom_validate(self):
from webnotes.utils import flt

self.doc.custom_field3 = flt(self.doc.custom_field1)*flt(self.doc.custom_field2)/1000





On Wed, Oct 10, 2012 at 2:28 PM, HF <h…@gmail.com> wrote:
How can I add a custom field to the sales order item document that can hold a mathematical equation of another fields ?


ex.: custom field 1 = fld1 and custom field 2 = fld2 and custom field 3 = fld3 I need the fld3 to hold this value == fld1*fld2/1000 just after entering the values in fld1 and fld2

is that possible? How ?



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

To post to this group, send email to er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/OZD91z8Qy9YJ.

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









Regards,
Nabin Hait






Regards,
Nabin Hait






Regards,
Nabin Hait



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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

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

 

 

Hi Nabin;


It doesn’t work !



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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/hNcjD4uOAeMJ.

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

 

 

Hi HF,

You will need to do a Tools > Clear Cache and Refresh after saving custom script for it to reflect.

Also, please keep the browser's console open to keep track of any errors in the script.

Thanks,
Anand.

On 10-Oct-2012, at 4:10 PM, HF <h....@gmail.com> wrote:

Hi Nabin;

It doesn't work !




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

To post to this group, send email to er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/hNcjD4uOAeMJ.

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

 

 




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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

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

 

 

Hi Nabin;


I did all that, but nothing happened, and no errors.



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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/KPXCqUskE0IJ.

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

 

 

Hi HF,

The script looks okay.

Here is a slightly more commented version

https://gist.github.com/3866677

Please check the field names.

- Rushabh


W: https://erpnext.com
T: @rushabh_mehta

On 10-Oct-2012, at 6:28 PM, HF <h....@gmail.com> wrote:

Hi Nabin;

I did all that, but nothing happened, and no errors.



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

To post to this group, send email to er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/KPXCqUskE0IJ.

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

 

 




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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

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

 

 


Hi Rushabh;


It still did not work, may be because this is a child table (sales order item) ?



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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/hCZHLRfAxzUJ.

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

 

 

Could be the issue. You need to refresh the table field in that case. Sorry its confusing. Ideally there should be a set_value method.


Just use

refresh_field("[table_field]")


On Thu, Oct 11, 2012 at 8:30 PM, HF <h....@gmail.com> wrote:

Hi Rushabh;

It still did not work, may be because this is a child table (sales order item) ?



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

To post to this group, send email to er…@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un…@googlegroups.com.


To view this discussion on the web visit https://groups.google.com/d/msg/erpnext-developer-forum/-/hCZHLRfAxzUJ.

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





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

To post to this group, send email to er...@googlegroups.com.

To unsubscribe from this group, send email to erpnext-developer-forum+un...@googlegroups.com.

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