discount from stock

Hello, I am very new and I need help, I have doctype with a child table in which I add items from stock, I want that when I validate the form, items added in the table are discounted from stock, is there any function or method to call? How would the structure for it be? , thanks I am very new and I would like to learn.