Repository navigation
[18.0][FIX] barcode_stock: avoid duplicate lines on rapid double scans #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
luisDIXMIT
wants to merge
1
commit into
OCA:18.0
Choose a base branch
from
dixmit:18.0-imp-barcode_stock
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+89
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
79 changes: 79 additions & 0 deletions
79
barcode_stock/static/tests/internal_transfer_double_scan.test.js
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import {beforeEach, describe, expect, test} from "@odoo/hoot"; | ||
| import {InternalTransferScreen} from "@barcode_stock/js/screens/internal_transfer_screen.esm"; | ||
| import {patchTranslations} from "@web/../tests/web_test_helpers"; | ||
|
|
||
| const LOTS = [ | ||
| {id: 21, name: "SN-0001"}, | ||
| {id: 22, name: "SN-0002"}, | ||
| ]; | ||
|
|
||
| /** | ||
| * An internal transfer screen without mounting it, whose lots for a product | ||
| * arrive only when `resolveLots` is called: the scans made before that are | ||
| * all waiting on the same request, as when a PDA reads a label twice. | ||
| * | ||
| * @returns {Object} the screen, its notifications and `resolveLots` | ||
| */ | ||
| function transferScreen() { | ||
| const screen = Object.create(InternalTransferScreen.prototype); | ||
| screen.state = {lines: []}; | ||
| screen.lotsCache = new Map(); | ||
| const notifications = []; | ||
| screen.notification = {add: (message) => notifications.push(String(message))}; | ||
| let resolveLots = null; | ||
| const lots = new Promise((resolve) => { | ||
| resolveLots = resolve; | ||
| }); | ||
| screen.fetchLots = () => lots; | ||
| return {screen, notifications, resolveLots: () => resolveLots(LOTS)}; | ||
| } | ||
|
|
||
| /** | ||
| * Scan `times` times without waiting for any scan to finish, then let the | ||
| * lots arrive and wait for them all. | ||
| */ | ||
| async function scanAtOnce({screen, resolveLots}, product, lot, times = 2) { | ||
| const scans = []; | ||
| for (let i = 0; i < times; i++) { | ||
| scans.push(screen.addLine(product, lot?.id || null, lot?.name || null, 1)); | ||
| } | ||
| resolveLots(); | ||
| await Promise.all(scans); | ||
| } | ||
|
|
||
| describe("BarcodeStock", () => { | ||
| beforeEach(() => patchTranslations()); | ||
|
|
||
| test("a serial scanned twice at once lands on a single line", async () => { | ||
| const transfer = transferScreen(); | ||
| const product = {id: 7, name: "Drill", tracking: "serial"}; | ||
| await scanAtOnce(transfer, product, LOTS[0]); | ||
| expect(transfer.screen.state.lines).toHaveLength(1); | ||
| expect(transfer.screen.state.lines[0]).toMatchObject({ | ||
| product_id: 7, | ||
| lot_id: 21, | ||
| qty: 1, | ||
| }); | ||
| expect(transfer.notifications).toEqual([ | ||
| "Serial number SN-0001 is already in this transfer.", | ||
| ]); | ||
| // Another serial of the same product still gets its own line. | ||
| await transfer.screen.addLine(product, LOTS[1].id, LOTS[1].name, 1); | ||
| const serials = transfer.screen.state.lines.map((line) => line.lot_id); | ||
| expect(serials).toEqual([21, 22]); | ||
| }); | ||
|
|
||
| test("a lot scanned twice at once adds up on a single line", async () => { | ||
| const transfer = transferScreen(); | ||
| const product = {id: 7, name: "Flour", tracking: "lot"}; | ||
| await scanAtOnce(transfer, product, LOTS[0]); | ||
| expect(transfer.screen.state.lines).toHaveLength(1); | ||
| expect(transfer.screen.state.lines[0]).toMatchObject({ | ||
| product_id: 7, | ||
| lot_id: 21, | ||
| qty: 2, | ||
| }); | ||
| expect(transfer.screen.state.lines[0].lots).toEqual(LOTS); | ||
| expect(transfer.notifications).toEqual([]); | ||
| }); | ||
| }); |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.