How to deal with replacement of sales invoice item or addition of more items to a sales invoice post delivery

Let’s assume I have a sales order with a value of 30,000 with item A that cost us 5,000 to manufacture.

I sold the item, received payment, shipped it, 5 days later the customer called me and complained that the item broke during use.
We told him to throw away the broken piece and that we would send him a replacement AND another item B to retain him. Manufacture of these new items in total cost us 10,000

Originally, my profit would have been 30,000 - 5,000 = 25,000 but since I had to manufacture replacements my profit is actually 30,000 - 5,000 - 10,000 = 15,000.

How do I book this profit properly with reference to the original sales order so I understand the true profit per order due to these additional manufacturing and shipping costs I had to incur for the same order.

Hi!! Does anyone have an answer to this?

Perhaps these links will help:

https://discuss.frappe.io/t/how-to-know-the-cost-of-a-sales-order/1751

https://docs.erpnext.com/docs/user/manual/en/accounts/accounting-reports

Based on the information in the second link I guess the best way is to update items in the sales order once need arises and create delivery notes for them without billing them in invoices.

Thanks for the input!!