Sales Invoice doesn't take correct quantity if there are multiple return via Delivery Note(Only the latest return is taken into consideration)

We created a delivery note with Item 1 as 1000.
First return is on the same day of 100 qty.
Second is 2 days later of 200 qty.
Third is 10 days later of 300 qty.
and Latest return of 1 qty.

When the Sales Invoice is created from the Delivery Note it doesn’t take date and pervious return made against the Delivery Note in to consideration.

Sales Invoice gets created shows qty as 1 even if you change the date while creating.