[FIX] deltatech_pos_stock: stock badge frozen on stale value in open sessions - #2834
Merged
Conversation
…sessions qty_available is a non-stored computed field, so a sale (which writes on stock.quant, not on product.template) never bumps the template's write_date. The POS incremental sync filters on write_date, so an already open session never receives the recalculated quantity again - the badge stays frozen at whatever was cached when the session was first loaded, sometimes for days. stock.quant now pushes a live STOCK_SYNCHRONISATION bus notification (same pos.bus.mixin channel core already uses for notify_synchronisation) whenever a product's on-hand quantity changes, to every open POS session with display_stock enabled. The frontend subscribes and merges the fresh product.template data straight into the in-memory model. Reproduced and confirmed on a production instance: badge showed a quantity that matched stock from several days earlier, not the current on-hand value. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The stock badge on the POS product card (
deltatech_pos_stock) could stay frozen at a stalequantity for days in an already open session, even after real sales depleted the stock.
Root cause:
qty_availableonproduct.templateis a non-stored computed field. A sale writeson
stock.quant, not onproduct.template, so the template'swrite_datenever changes. ThePOS incremental sync (
pos.load.mixin) filters strictly onwrite_date > last_server_date, soan already open session never gets the recalculated quantity re-sent - the badge stays at
whatever value was cached when the session's data was first loaded.
Reproduced and confirmed on a production instance (Damira): the badge showed a quantity that
matched real on-hand stock from several days earlier, not the current value, even though the
POS session had been opened fresh that same day.
Fix
stock.quantnow pushes a liveSTOCK_SYNCHRONISATIONbus notification - reusing the samepos.bus.mixinchannel core already uses forpos.config.notify_synchronisation(POS devicesync) - whenever a product's on-hand
quantitychanges, to every open POS session withdisplay_stockenabled. The frontend subscribes to this channel and merges the freshproduct.templatedata straight into the in-memory model, independent of thewrite_date-basedsync cycle.
Only
quantitychanges trigger a notification (notreserved_quantity), since the badge showson-hand stock (
qty_available), not the forecasted/reserved quantity.Test plan
deltatech_pos_stock+ demo data): existing badge testpasses unchanged.
test_stock_badge_updates_live_without_reload: opens a POS session, confirms theinitial badge value, then changes the product's stock quantity via RPC (simulating a sale
from another till/channel) while the session stays open, and asserts the badge updates
to the new value without any page reload.
notification call and confirmed the test fails (badge stays at the old value); restored
the fix and both tests pass again.
pre-commit(ruff, eslint, pylint-odoo, prettier) passes clean.Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com