Repository navigation
fix(items): prevent corrupt average cost when receiving against negative stock - #4838
VighneshNilajakar wants to merge 1 commit into
Conversation
Skip weighted-average cost calculation when stock is missing or negative, or when received/total quantities are non-positive. Use the newly received price instead, preventing invalid cost prices and division by zero during receiving. Add regression coverage for positive, zero, and negative stock.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Summary
Item::change_cost_price()against missing or negative old stock, non-positive received quantity, and non-positive total quantity.Root cause
change_cost_price()included negative stock in the weighted-average denominator. Receiving stock while inventory was negative could therefore produce nonsensicalcost_pricevalues, which were later snapshotted intoospos_sales_items.item_cost_price.Tests
vendor/bin/phpunit tests/Models/ItemTest.php tests/Models/ReceivingTest.php- 11 tests, 34 assertionsvendor/bin/phpunit tests/Models- 119 tests, 286 assertionsNotes
ospos_sales_items.item_cost_pricevalues may already be corrupted and require a separate, reviewed data-repair process.Summary by CodeRabbit