How to update child table of a item table

1,278 views
Skip to first unread message

Addy

unread,
May 25, 2013, 5:38:20 AM5/25/13
to erpnext-dev...@googlegroups.com
Hi, 

I would like to update a child table of the item master via custom script and I am unable to figure out a way to do so. Basically, I am looking to update the item website specification table automatically since all the details are there in my item master vide custom fields.

Now I think that the command 

webnotes.conn.set_value("Item Website Specification", ?? , "label", "Material")
webnotes.conn.set_value("Item Website Specification", ?? , "description", self.doc.base_material)

should work but I am stuck at this since I am unable to find a way to know the id of the child table, since I want this value to update the first row of the table.

Any suggestions.

Regards,

Aditya Duggal

Nabin Hait

unread,
May 25, 2013, 7:19:57 AM5/25/13
to erpnext-dev...@googlegroups.com
You should use "addchild()" function to add a new row in child table.
For example you can check add_default_uom_in_conversion_factor_table() function in item.py file. Basically addchild() function create an document object for row and return it. Then you can assign any column value using that object.

--
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...@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/msgid/erpnext-developer-forum/e0f1a9b8-ff56-4e7a-862c-cd1c231b979c%40googlegroups.com?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Addy

unread,
May 25, 2013, 9:10:41 AM5/25/13
to erpnext-dev...@googlegroups.com
Thanks Nabin for the info.

I have tried to run the below mentioned code but I guess something is wrong, though I am not getting any error code.

def fn_add_item_website_specifications(self):
web_specs = [d.label for d in self.doclist.get({"parentfield": "item_website_specification"})]
if "H" not in web_specs:
ch = addchild(self.doc, 'item_website_specification', 'Item Website Specification', self.doclist)
ch.label = "H"
ch.description = self.doc.height_dia

Surely I have called the function as self.fn_add_item_website_specifications

Another couple of queries are:
  • How could I ensure that if "H" exists in Label then the value for the same is updated in the system against that item since I could not find any code for the same in the item.py file.
  • self.doc.web_long_description = desc_web where desc_web is a String. Now this is supposed to update the website description every time the item is edited but it does so only once and if we delete the website description then it does not update the description, again I am not getting any error code.

On Saturday, May 25, 2013 4:49:57 PM UTC+5:30, Nabin Hait wrote:
You should use "addchild()" function to add a new row in child table.
For example you can check add_default_uom_in_conversion_factor_table() function in item.py file. Basically addchild() function create an document object for row and return it. Then you can assign any column value using that object.

On 25-May-2013, at 3:08 PM, Addy wrote:

Hi, 

I would like to update a child table of the item master via custom script and I am unable to figure out a way to do so. Basically, I am looking to update the item website specification table automatically since all the details are there in my item master vide custom fields.

Now I think that the command 

webnotes.conn.set_value("Item Website Specification", ?? , "label", "Material")
webnotes.conn.set_value("Item Website Specification", ?? , "description", self.doc.base_material)

should work but I am stuck at this since I am unable to find a way to know the id of the child table, since I want this value to update the first row of the table.

Any suggestions.

Regards,

Aditya Duggal

--
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+unsub...@googlegroups.com.

Rushabh Mehta

unread,
May 27, 2013, 1:44:21 AM5/27/13
to erpnext-dev...@googlegroups.com
I have tried to run the below mentioned code but I guess something is wrong, though I am not getting any error code.

def fn_add_item_website_specifications(self):
web_specs = [d.label for d in self.doclist.get({"parentfield": "item_website_specification"})]
if "H" not in web_specs:
ch = addchild(self.doc, 'item_website_specification', 'Item Website Specification', self.doclist)
ch.label = "H"
ch.description = self.doc.height_dia

Surely I have called the function as self.fn_add_item_website_specifications

did you call it with a () in the end? as in self.fn_add_item_website_specifications()

also, try an put a msgprint if it shows up.


 
Another couple of queries are:
  • How could I ensure that if "H" exists in Label then the value for the same is updated in the system against that item since I could not find any code for the same in the item.py file.
  • self.doc.web_long_description = desc_web where desc_web is a String. Now this is supposed to update the website description every time the item is edited but it does so only once and if we delete the website description then it does not update the description, again I am not getting any error code.

On Saturday, May 25, 2013 4:49:57 PM UTC+5:30, Nabin Hait wrote:
You should use "addchild()" function to add a new row in child table.
For example you can check add_default_uom_in_conversion_factor_table() function in item.py file. Basically addchild() function create an document object for row and return it. Then you can assign any column value using that object.

On 25-May-2013, at 3:08 PM, Addy wrote:

Hi, 

I would like to update a child table of the item master via custom script and I am unable to figure out a way to do so. Basically, I am looking to update the item website specification table automatically since all the details are there in my item master vide custom fields.

Now I think that the command 

webnotes.conn.set_value("Item Website Specification", ?? , "label", "Material")
webnotes.conn.set_value("Item Website Specification", ?? , "description", self.doc.base_material)

should work but I am stuck at this since I am unable to find a way to know the id of the child table, since I want this value to update the first row of the table.

Any suggestions.

Regards,

Aditya Duggal

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

--
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...@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.
 
 



--



Twitter: @rushabh_mehta

Addy

unread,
Jun 9, 2013, 5:21:59 PM6/9/13
to erpnext-dev...@googlegroups.com
Hi Rushabh,

Seems like the code is running fine. I have checked the report on item website specification and found out that the code is running properly but the field generated by the server script is not showing in the item but it shows up in the report.

Let me know what is to be done by me or is it a bug. 

PS: I have tried to clear cache and refresh but still the filed created by the script is not showing up.
To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr...@googlegroups.com.

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

Addy

unread,
Jun 9, 2013, 5:24:39 PM6/9/13
to erpnext-dev...@googlegroups.com
Another thing I have noticed is that the field created by the server script does not show up in the website as well.

Rushabh Mehta

unread,
Jun 10, 2013, 1:08:59 AM6/10/13
to erpnext-dev...@googlegroups.com
Are you mis-typing the fieldname? Is it hidden? Can't think of anything else. If its there in the database, it should show up in the form.


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

Aditya Duggal

unread,
Jun 10, 2013, 1:52:20 AM6/10/13
to erpnext-dev...@googlegroups.com
How could the field be hidden, I am unable to find a reason for not able to view only that field which is created by server script other fields in the table for the same item are showing properly which were created manually.

Here are the screen shots:

For Item
Inline image 1

For Item Website specification Report:

Inline image 2


And Finally the screen shot of the webpage of the item:


Inline image 3



image.png
image.png
image.png

Anand Doshi

unread,
Jun 10, 2013, 1:56:04 AM6/10/13
to erpnext-dev...@googlegroups.com
Hi Aditya,

In what function have you written the server script?

Possibly, after adding the children, the Item record is not getting saved.

Thanks,
Anand.

On 10-Jun-2013, at 11:22 AM, Aditya Duggal <adi...@rigpl.com> wrote:

How could the field be hidden, I am unable to find a reason for not able to view only that field which is created by server script other fields in the table for the same item are showing properly which were created manually.

Here are the screen shots:

For Item
<image.png>

For Item Website specification Report:

<image.png>


And Finally the screen shot of the webpage of the item:


<image.png>

Aditya Duggal

unread,
Jun 10, 2013, 2:02:19 AM6/10/13
to erpnext-dev...@googlegroups.com
Hi Anand,

The function for the website specifications is below which is called on line no: 536 of gist

self.fn_add_item_website_specifications()

The function is defined in line no: 377.

Let me know if you find the anomaly.



Rushabh Mehta

unread,
Jun 10, 2013, 2:04:03 AM6/10/13
to erpnext-dev...@googlegroups.com
Aditya,

Can you send your latest script on gist?

You need to set 3 properties to make it show correctly as a child record: parent, parenttype, parentfield

It seems one of those fields is not set correctly

best,
Rushabh


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

On 10-Jun-2013, at 11:22 AM, Aditya Duggal <adi...@rigpl.com> wrote:

<image.png>

Aditya Duggal

unread,
Jun 10, 2013, 2:12:40 AM6/10/13
to erpnext-dev...@googlegroups.com
The latest gist in the last post of mine maybe we were typing at the same time anyhow I am still sending the link for the same.

Here is the latest GIST

Also I am not able to understand the requirement for 3 fields since in the item website specification I can see only one field which is parent.

Here is the function which I am using to update the item website specification table.

def fn_add_item_website_specifications(self):
webnotes.msgprint("Function Line 1")
web_specs = [d.label for d in self.doclist.get({"parentfield": "item_website_specification"})]
webnotes.msgprint(web_specs)
if "H" not in web_specs:
ch = addchild(self.doc, 'item_website_specification', 'Item Website Specification', self.doclist)
ch.label = "H"
ch.description = self.doc.height_dia

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

Rushabh Mehta

unread,
Jun 10, 2013, 2:17:08 AM6/10/13
to erpnext-dev...@googlegroups.com
Aditya,

There is a typo in the table fieldname

ch = addchild(self.doc, 'item_website_specifications', 'Item Website Specification', self.doclist)

It should be item_website_specifications with an "s" at the end.

In future, we will throw a validation if such a typo exists.

best,
Rushabh



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

Aditya Duggal

unread,
Jun 10, 2013, 4:01:40 AM6/10/13
to erpnext-dev...@googlegroups.com
Thanks Rushabh

That typo has caused a lot of delays for me.....ahhh what a small oversight can do
.


Addy

unread,
Jun 10, 2013, 8:23:46 AM6/10/13
to erpnext-dev...@googlegroups.com
Hi,

Now I just wanted to know if it is possible to update the child table if a value exists since we are adding a new value if the item does not exist.
The print value of [d] is:

[{u'__islocal': None, u'description': 9.5250000000000004, u'parent': u'H1SQR3PN9', u'__newname': None, u'creation': u'2013-06-10 17:47:00', u'modified': '2013-06-10 17:48:50', u'__modified': None, u'owner': u'Administrator', u'_user_tags': None, u'modified_by': u'Administrator', u'name': u'000217854', u'idx': 7, u'__temp': None, u'doctype': u'Item Website Specification', u'label': None, u'parenttype': u'Item', u'docstatus': 0, u'parentfield': u'item_website_specifications'}]

Basically I want to modify my code as below but I am unable to fetch the name of the line in child table:

if "H (mm)" not in web_specs:
ch = addchild(self.doc, 'item_website_specifications', 'Item Website Specification', self.doclist)
ch.label = "H (mm)"
ch.description = self.doc.height_dia
else:
ch = amend(self.doc, 'item_website_specifications', 'Item Website Specification', self.doclist)
ch.description = self.doc.height_dia where item_website_specifications.name = d[10]
Something on the above lines but I am not sure about 2 things one is amend part marked in red and also how to call the id of the line since d[10] would throw an error.

On Monday, June 10, 2013 1:31:40 PM UTC+5:30, Addy wrote:
Thanks Rushabh

That typo has caused a lot of delays for me.....ahhh what a small oversight can do
.
Aditya,

There is a typo in the table fieldname

ch = addchild(self.doc, 'item_website_specifications', 'Item Website Specification', self.doclist)

It should be item_website_specifications with an "s" at the end.

In future, we will throw a validation if such a typo exists.

best,
Rushabh



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

The latest gist in the last post of mine maybe we were typing at the same time anyhow I am still sending the link for the same.

Here is the latest GIST

Also I am not able to understand the requirement for 3 fields since in the item website specification I can see only one field which is parent.

Here is the function which I am using to update the item website specification table.

def fn_add_item_website_specifications(self):
webnotes.msgprint("Function Line 1")
web_specs = [d.label for d in self.doclist.get({"parentfield": "item_website_specification"})]
webnotes.msgprint(web_specs)
if "H" not in web_specs:
ch = addchild(self.doc, 'item_website_specification', 'Item Website Specification', self.doclist)
ch.label = "H"
ch.description = self.doc.height_dia
On Mon, Jun 10, 2013 at 11:34 AM, Rushabh Mehta <rme...@gmail.com> wrote:
Aditya,

Can you send your latest script on gist?

You need to set 3 properties to make it show correctly as a child record: parent, parenttype, parentfield

It seems one of those fields is not set correctly

best,
Rushabh


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

On 10-Jun-2013, at 11:22 AM, Aditya Duggal 

<image.png>


--
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+unsub...@googlegroups.com.
To post to this group, send email to erpnext-developer-forum@googlegroups.com.

--
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+unsub...@googlegroups.com.
To post to this group, send email to erpnext-developer-forum@googlegroups.com.

--
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+unsub...@googlegroups.com.
To post to this group, send email to erpnext-developer-forum@googlegroups.com.

Anand Doshi

unread,
Jun 10, 2013, 8:40:12 AM6/10/13
to erpnext-dev...@googlegroups.com
Hi Aditya,

You can use:
ch = self.doclist.getone({"parent field": "item_website_specifications", "label": "H (mm)"})
ch.description = something

in the else part.

Thanks,
Anand.

To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer...@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/msgid/erpnext-developer-forum/3ffc93f4-1503-471e-987c-39bd99ec5ed1%40googlegroups.com?hl=en.

Anand Doshi

unread,
Jun 10, 2013, 8:41:31 AM6/10/13
to Anand Doshi, erpnext-dev...@googlegroups.com
correction:

ch = self.doclist.getone({"parentfield": "item_website_specifications", "label": "H (mm)"})
ch.description = something
Reply all
Reply to author
Forward
0 new messages