Try ERPNext Try Frappe Cloud Buy Support Partners Foundation

[Tutorial ] working with child table with python

here is an easy way to work with child tables from backend

to remove all rows

to_remove = []
for d in doc.get("uoms"):
    #remove rows with condition ,  you can drop the if checking and append to the list right away to remove them all 
	if d.conversion_factor == 1 and d.uom != self.stock_uom:        

[doc.remove(d) for d in to_remove]

to add new row

    row = doc.append('uoms', {})
    row.uom = "SXM"
    row.conversion_factor = 12

for changing current row value

for d in doc.get("uoms"):
    if d.uom == "SXM":
        d.conversion_factor = 13

if there is another ways or additional hints please add it

if you want to remove all rows easy way is

def validate(self):
    self.uoms = []

If you want to get the rows filtered by a condition

def validate(self):
    for d in self.get('uoms', {'uom': 'SXM'}):
        d.conversion_factor = 13.0

Also to remove certain rows given a condition

def validate(self):
    [self.uoms.remove(d) for d in self.get('uoms') if d.conversion_factor == 1 and d.uom != d.stock_uom]

I am experiencing a very strange issue here with child tables Weird behavior while removing child record using self.remove in ERPNext: v12.9.3 (master)

Can anyone help please