I have written a piece of Python code to depict what I was suggesting as the solution, but for some reason this doesn’t work in appsheet, probably because it has no provision for recognising objects. But this is kind of what I am going for.
class item:
def __init__(self, name, UoM, inner, exact_stock, create=True):
self.total_stock = 0
self.exact_stock = exact_stock
self.UoM = UoM
self.name = name
self.inner = inner
self.parent = None
self.child = None
def set_child_parent(self,child=None):
# child = item(create) if child is None else child #if no child then create new child otherwise put child item. by default
self.child = child
self.child.parent = self
def calculate_total_stock(self):
if self.parent:
temp = self.parent.total_stock * self.parent.inner
print("Temp value for "+self.name+" = "+str(temp))
self.total_stock = self.exact_stock + temp
else:
self.total_stock = self.exact_stock
return self.total_stock
a = item("item A","pcs", 12, 5)
b = item("item B","pcs", 15, 3)
c = item("item C","pcs", 45, 4)
a.set_child_parent(b)
b.set_child_parent(c)
print("Name: "+a.name+", Child: "+a.child.name+", Inner Qty:"+str(a.inner)+" "+a.child.UoM+", Exact Stock: "+str(a.exact_stock))
print("Name: "+b.name+", Child: "+b.child.name+", Parent: "+b.parent.name+", Inner Qty:"+str(b.inner)+" "+b.child.UoM+", Exact Stock: "+str(b.exact_stock))
print("Name: "+c.name+", Parent: "+c.parent.name+", Inner Qty:"+str(c.inner)+", Exact Stock: "+str(c.exact_stock))
print(a.name+", Total Stock: "+str(a.calculate_total_stock()))
print(b.name+", Total Stock: "+str(b.calculate_total_stock()))
print(c.name+", Total Stock: "+str(c.calculate_total_stock()))
Output:
Name: item A, Child: item B, Inner Qty:12 pcs, Exact Stock: 5
Name: item B, Child: item C, Parent: item A, Inner Qty:15 pcs, Exact Stock: 3
Name: item C, Parent: item B, Inner Qty:45, Exact Stock: 4
item A, Total Stock: 5
Temp value for item B = 60
item B, Total Stock: 63
Temp value for item C = 945
item C, Total Stock: 949