In expense invoice product should have a batch number when purchase an invoice and also in sales invoice to track and calculate a specific batch for profit and loss.
For example:
I’ve purchased a product “abc” for 5 dollars, and I’ve purchased same product “abc” for second time for 6 dollars and sold with different price. So now i can track and calculate the different batches profit and loss better and easier.