There is a problem that got me confused about updating the stock quantity in a safe way. A simple scenario, suppose I have 10 of product X in warehouse and there is zero orders so, also in Magento inventory I have 10 pieces. Suppose that I received another 10 pieces, and when I opened the product inventory to change 10 to 20, some customer placed and order and then I pressed the submit button. As a result Magento inventory will show that I have 20 pieces while I actually have 19.
I tried to write a module to update the product programmatically. But this solution may reduce the risk, because it will use the value + what I want to add. So it adding not replacing. But also there is a risk.
A second thought is to do it in the database level by preforming a
SQL UPDATE STATEMENT, but I found another risk of doing it, I need to update more than one row in a table and more than one table. The data may be inconsistent.
Is there a way to use the lock method, like locking the product until the update occur, or another work around ?
After I tested Magento with this test case: I have 6 pieces, I opened the product inventory then changed the 6 with 7 without pressing the submit button. Then I ordered the 6 of them. Then I pressed submit in the product page, Magento shows that I have 1 in stock not seven which is correct. But is it guaranteed? And can I have an explanation how Magento handle it?