Updating rates on submitted purchase receipts regularly

I am trying to develop a more convenient way to updates item rates on Purchase Receipt Items and have those changes propagate properly (ie, via Repost Item Valuation).

I know this is not normally something that should have to happen, but there are two things outside of our control causing these rates to be wrong on a regular bases. I think the (reasonable) assumption made by ERPNext is that the item rate on the PO is final. But we continually have suppliers change their rates from the time we send them the PO to the time we receive the items. Now at that point I know we can enter a new rate on the Purchase Receipt, but what also happens sometimes is that we don’t get the invoice until a week or so after the stock has arrived. Thus, we have to submit the Purchase Receipt to get the stock into the system, bu then later find out that the price from the PO is not correct. I know also that you can then cancel and amend the Purchase Receipt, but once the stock starts getting used, that becomes much more challenging to do. I cannot expect my users to know how to manage that situation.

Another factor for us is that we work in two different currencies. We enter the desired exchange rate on the PO, and again on the Purchase Receipt, but by the time we get the invoice, the exchange rate may have changed, so again, the Purchase Receipt needs to be cancelled and amended. This becomes very difficult to do once the stock has been used.

So, I was hoping to write a function to allow the user to click a button the the Purchase Receipt that would allow them to update the exchange rate and item rates, then disable the normal validation checks to save the changes. But of course I still want to make sure the changes are propagated properly through the stock ledger and valuation system. I do NOT expect to change the quantity though this function.

So my question is, how can I properly trigger (in python code) re-evaluating a modified Purchase Receipt in a way that makes it look like the the PR was cancelled and amended, but without the hassle of actually doing that and dealing with all the stock issues?

I did see this article, which mentioned using Landed Cost Vouchers to adjust the rates, but I’m not sure how I would use that exactly, any further explanation on that route (if that’s a better way) would be helpful also.

Thank you.

After some more digging, I’ve discovered some settings in Buying Settings that seem to address this case. Unchecking “Maintain Same Rate Throughout the Purchase Cycle” and checking " Set Landed Cost Based on Purchase Invoice Rate" allows me to create a Purchase Invoice with a different rate. Upon submitting this, the valuation rates are updated in the stock ledger.