function compute(doc, cdt, cdn){
if (doc.width_mm && doc.height_mm){ //it's check if the fields contains a value
doc.result_field = doc.width_mm * doc.height_mm;
}
}
cur_frm.cscript.custom_width_mm = compute;
cur_frm.cscript.custom_height_mm = compute;
--
You received this message because you are subscribed to the Google Groups "ERPNext User's Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-user-fo...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
you can add a custom script inside the your calculation fields base:function compute(doc, cdt, cdn){ if (doc.width_mm && doc.height_mm){ //it's check if the fields contains a value doc.result_field = doc.width_mm * doc.height_mm; } } cur_frm.cscript.custom_width_mm = compute; cur_frm.cscript.custom_height_mm = compute;
Hi,I want to add a custom field to the Item doctype that is a calculated field. It is the product of the multiplication of two other fields on the same object.Here's an example where I have two custom fields on Item:width_mmheight_mmI want to add a new field called area which is the product of width_mm * height_mmWhat's the erpnext way of achieving this?Thanks,-Jev
--
You received this message because you are subscribed to the Google Groups "ERPNext User's Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-user-forum+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Hi, Jev! You are right!
You must edit the code controler, in “mydoctype.py” i.e “accounts/doctype/account/account.py”
You must a custom code, inside the Doctype class
It is interesting that at the time of your validation function is called, see the code below.
https://github.com/webnotes/erpnext/blob/develop/accounts/doctype/account/account.py#L28
I refer to the validation because it does not matter if your doctype is being created or updated.
Your code would look something like below
from webnotes import cflt
class DocType:
def validate(self):
....
self.compute()
def compute(self):
if not self.doc.height_mm or not self.doc.width_mm:
msgprint(_('Please, input the width and the height!'), raise_exception=1)
# raise_exception=1 stops the code, and raise the error
self.doc.computed_field = cflt(self.doc.width_mm) * cflt(self.doc.height_mm)
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-user-fo...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-user-forum+unsubscribe@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 User's Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-user-forum+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
--
You received this message because you are subscribed to a topic in the Google Groups "ERPNext User's Forum" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/erpnext-user-forum/TLhFXnBiWS0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to erpnext-user-fo...@googlegroups.com.
--
You received this message because you are subscribed to the Google Groups "ERPNext User's Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-user-fo...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-user-forum+unsub...@googlegroups.com.