How to handle fractions on the forms and convert them to decimals?

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:

  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.



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 post to this group, send email to er...@googlegroups.com.

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

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

 

 

Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to er…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

 

 

Hi Anand,


Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad…@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

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

 

 

Make sure that height_dia_inch is of type Data and height_dia is if type float. 

When you enter value in height_dia_inch as a fraction. The code will set its decimal value in height_dia. 

I have tried this code. Maybe you didn't clear cache. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

 

 

By any chance, are these fields located in a table? The code I have given works for main form and doesn't work in table. It would be different for table. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

 

 

Hi,

The set_value part should be like this:

cur_frm.set_value("height_dia", eval(doc.height_dia_inch));


Regards,
Nabin Hait

On 20-Apr-2013, at 3:50 PM, Anand Doshi wrote:

By any chance, are these fields located in a table? The code I have given works for main form and doesn't work in table. It would be different for table. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

 

 

You are correct Nabin, I was missing the quotes in my code and also referring it with doc, thanks alot for the same. But this has given rise to another question that is I am unable to use the following code since math is not defined.

cur_frm.set_value(“height_dia”, math.round(eval(doc.height_dia_inch)*25400)/1000);

@Anand: yes thes fields are in the doctype…I did not knew that we could add fields in the form which are not part of the doctype (table)



On Saturday, April 20, 2013 3:58:44 PM UTC+5:30, Nabin Hait wrote:
Hi,

The set_value part should be like this:

cur_frm.set_value(“height_dia”, eval(doc.height_dia_inch));



Regards,
Nabin Hait

On 20-Apr-2013, at 3:50 PM, Anand Doshi wrote:

By any chance, are these fields located in a table? The code I have given works for main form and doesn't work in table. It would be different for table. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to er…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

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

 

 

It should be Math.round(), case sensitive.

On 20-Apr-2013, at 4:17 PM, Aditya Duggal wrote:

You are correct Nabin, I was missing the quotes in my code and also referring it with doc, thanks alot for the same. But this has given rise to another question that is I am unable to use the following code since math is not defined.

cur_frm.set_value("height_dia", math.round(eval(doc.height_dia_inch)*25400)/1000);

@Anand: yes thes fields are in the doctype....I did not knew that we could add fields in the form which are not part of the doctype (table)


On Saturday, April 20, 2013 3:58:44 PM UTC+5:30, Nabin Hait wrote:
Hi,

The set_value part should be like this:

cur_frm.set_value("height_dia", eval(doc.height_dia_inch));


Regards,
Nabin Hait

On 20-Apr-2013, at 3:50 PM, Anand Doshi wrote:

By any chance, are these fields located in a table? The code I have given works for main form and doesn't work in table. It would be different for table. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to er…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

 

 

It should be Math with M capital. 

Math.round will round the number to nearest integer. It won't round the number to nearest decimal.

If you want to restrict output to 2 decimals, use flt(val, 2)

Sent from my phone

On 20-Apr-2013, at 4:17 PM, Aditya Duggal <ad...@gmail.com> wrote:

You are correct Nabin, I was missing the quotes in my code and also referring it with doc, thanks alot for the same. But this has given rise to another question that is I am unable to use the following code since math is not defined.

cur_frm.set_value("height_dia", math.round(eval(doc.height_dia_inch)*25400)/1000);

@Anand: yes thes fields are in the doctype....I did not knew that we could add fields in the form which are not part of the doctype (table)


On Saturday, April 20, 2013 3:58:44 PM UTC+5:30, Nabin Hait wrote:
Hi,

The set_value part should be like this:

cur_frm.set_value("height_dia", eval(doc.height_dia_inch));


Regards,
Nabin Hait

On 20-Apr-2013, at 3:50 PM, Anand Doshi wrote:

By any chance, are these fields located in a table? The code I have given works for main form and doesn't work in table. It would be different for table. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to er…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

 

 

OMG I would really have to get used to the case sensitivity of coding. Thanks a lot for pointing out this silly mistake.

On Saturday, April 20, 2013 4:20:08 PM UTC+5:30, Nabin Hait wrote:

It should be Math.round(), case sensitive.

On 20-Apr-2013, at 4:17 PM, Aditya Duggal wrote:

You are correct Nabin, I was missing the quotes in my code and also referring it with doc, thanks alot for the same. But this has given rise to another question that is I am unable to use the following code since math is not defined.

cur_frm.set_value("height_dia", math.round(eval(doc.height_dia_inch)*25400)/1000);

@Anand: yes thes fields are in the doctype....I did not knew that we could add fields in the form which are not part of the doctype (table)


On Saturday, April 20, 2013 3:58:44 PM UTC+5:30, Nabin Hait wrote:
Hi,

The set_value part should be like this:

cur_frm.set_value("height_dia", eval(doc.height_dia_inch));


Regards,
Nabin Hait

On 20-Apr-2013, at 3:50 PM, Anand Doshi wrote:

By any chance, are these fields located in a table? The code I have given works for main form and doesn't work in table. It would be different for table. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to er…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

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

 

 

Thanks Anand


For introducing me to flt but I have already done the calculation in the round to get me 3 decimal places. Once again thank you all for the help.

On Saturday, April 20, 2013 4:22:41 PM UTC+5:30, Anand Doshi wrote:
It should be Math with M capital. 

Math.round will round the number to nearest integer. It won’t round the number to nearest decimal.

If you want to restrict output to 2 decimals, use flt(val, 2)

Sent from my phone

On 20-Apr-2013, at 4:17 PM, Aditya Duggal <ad…@gmail.com> wrote:

You are correct Nabin, I was missing the quotes in my code and also referring it with doc, thanks alot for the same. But this has given rise to another question that is I am unable to use the following code since math is not defined.

cur_frm.set_value(“height_dia”, math.round(eval(doc.height_dia_inch)*25400)/1000);

@Anand: yes thes fields are in the doctype…I did not knew that we could add fields in the form which are not part of the doctype (table)


On Saturday, April 20, 2013 3:58:44 PM UTC+5:30, Nabin Hait wrote:
Hi,

The set_value part should be like this:

cur_frm.set_value(“height_dia”, eval(doc.height_dia_inch));



Regards,
Nabin Hait

On 20-Apr-2013, at 3:50 PM, Anand Doshi wrote:

By any chance, are these fields located in a table? The code I have given works for main form and doesn't work in table. It would be different for table. 

Sent from my phone

On 20-Apr-2013, at 3:39 PM, Aditya Duggal <ad...@gmail.com> wrote:

Hi Anand,

Thanks for the quick response, I have tried the below code replacing the requisite quotes but there seems to be nothing happening, do I need to call this function from another function or it should work without being called. The part of code I am using is below:


cur_frm.cscript.height_dia_inch = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(doc.height_dia, eval(doc.height_dia_inch));
}

On Saturday, April 20, 2013 11:34:52 AM UTC+5:30, Anand Doshi wrote:
Hi Aditya,

Create a custom field of type Data. Say the fieldname is field_fraction.
Assuming that the decimal fieldname is field_decimal

Now, write a function like:
cur_frm.cscript.field_fraction = function(doc) {
// suppose value of field_fraction = 4/5
// then value of field_decimal will be set as 0.8
cur_frm.set_value(field_decimal, eval(doc.field_fraction));
}

Thanks,
Anand.

On 20-Apr-2013, at 11:07 AM, Aditya Duggal <ad...@gmail.com> wrote:

Hi,

I have been trying to figure out a way to capture data which is in fraction but honestly cannot really figure out which field to use and how to keep fractional and decimal data in the database.

Now my problem is that I am trying to capture some dimensions and as all of you might be aware that dimensions can be in various units but in my industry the dimensions are either in mm or inch.

Now till now we are capturing all the data in mm and not in inch we generally convert the inch data manually but this creates a lot of trouble. Now entering mm data is simple which happens to be a float but when it comes to Inch data capturing we  are talking about fractions as well. Is it possible to capture the data in a form in Inch aka fractions and then save both the data in the table.

For example: we need to enter 1/2" then there are 2 ways of doing it:
  • Easier way: Make a form with float input field and ask the user to convert the fraction into decimal and then enter the data.
    • Benefit of this method is only one which is less coding for the developer.
  • Tougher way: Make a form with FRACTION input field and ask the user to enter the fraction only, now there would be another field in decimal which would be hidden from the user and the code would be run to convert the fraction to the decimal and both the values would be saved.

Now my question is that how could be handle such a situation in erpnext.




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 post to this group, send email to er…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

To post to this group, send email to erpnext-dev…@googlegroups.com.

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

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 unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

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

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

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