Why the sales invoice sometimes insert the valuation rate instead of selling rate

what is the source of the problem:
when i make a sales invoice and insert the items sometimes the system inserts the valuation rate in the invoice instead of the selling rate and that causes a huge problem in my accounting list.

P.S when i check the item in the command “edit” it reveals in the ‘discount and merge’ bar that the item is making an automatic discount?
why is that?