[data migration] accounting cost entry and reverse cost entry in moving average case

If we are going to start system from scratch, we key-in the opening receipt but not yet invoiced.

After that we adjust the opening balance.

How can we post reverse the cost entry to the correct amount when we post invoice ??

Example :

Step1 : When we receipt, Ax post cost entry

receipt : cost entry

Dr Sales, packing slip offset wrong cost price

Cr Order, packing slip wrong cost price

Step2 : GL is adjusted. Cost price is adjusted.

Step3 : When we post invoice, Ax will reverse the cost entry amount.

This makes our GL posting not correct since it reverse the old cost price ??

invoice : reverse the cost entry

Dr Order, packing slip wrong cost price

Cr Sales, packing slip offset wrong cost price

We are not sure how to make the GL correct for the starting system that contains some cost price, since the cost price is varied.