If you bought the same product at different prices on different dates, which purchase cost you write when you sell it is a choice. Under weighted average, all receipts are averaged and issues are valued at that average. Under FIFO, first in is first out: every receipt opens a layer and a sale consumes the oldest layer first.
In periods when prices climb quickly the two methods drift noticeably apart. FIFO consumes the old, cheaper cost first, so it shows a higher profit on paper; weighted average smooths the swings. The question is not which one is correct but which one describes your business more honestly.
The method is picked in the stock settings and the costing engine runs immediately before saving. When you enter a back dated purchase or delete a movement, every cost after that date is recalculated, which is why an old invoice entered mid month also corrects past profit. If you change the method, the recalculation button in the settings rewrites the entire history under the new one.