Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,19 @@ export class InternalTransferScreen extends Component {
await this.addSerialLine(product, lotId, lotName);
return;
}
const lots =
product.tracking === "none" ? [] : await this.getProductLots(product.id);
const existing = this.state.lines.find(
(l) => l.product_id === product.id && l.lot_id === lotId
);
if (existing) {
// The input hands an edited quantity back as text.
existing.qty = roundQty((parseFloat(existing.qty) || 0) + qty);
if (existing.tracking !== "none" && !existing.lots?.length) {
existing.lots = [...(await this.getProductLots(product.id))];
existing.lots = [...lots];
}
return;
}
const lots =
product.tracking === "none"
? []
: [...(await this.getProductLots(product.id))];
this.state.lines.push(
ensureLineUid({
product_id: product.id,
Expand All @@ -214,7 +212,7 @@ export class InternalTransferScreen extends Component {
tracking: product.tracking,
lot_id: lotId,
lot_name: lotName,
lots: lots,
lots: [...lots],
})
);
}
Expand All @@ -239,6 +237,8 @@ export class InternalTransferScreen extends Component {
* the operator to choose the serial on, never a second unit on another.
*/
async addSerialLine(product, lotId, lotName) {
const lots = await this.getProductLots(product.id);
// From here on there is no await: the check and the push run atomically
if (
lotId &&
this.state.lines.some(
Expand All @@ -262,7 +262,7 @@ export class InternalTransferScreen extends Component {
tracking: product.tracking,
lot_id: lotId,
lot_name: lotName,
lots: [...(await this.getProductLots(product.id))],
lots: [...lots],
})
);
}
Expand Down
5 changes: 3 additions & 2 deletions barcode_stock/static/tests/quantity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ describe("BarcodeStock", () => {

test("an internal transfer line adds up scans and an edited quantity", async () => {
const screen = Object.create(InternalTransferScreen.prototype);
const product = {id: 7, tracking: "none"};

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test for the double scan itself, with a lot and with a serial?

const line = {product_id: 7, lot_id: false, qty: 0.1, tracking: "none"};
screen.state = {lines: [line]};
await screen.addLine({id: 7}, false, false, 0.2);
await screen.addLine(product, false, false, 0.2);
expect(line.qty).toBe(0.3);
// The input hands an edited quantity back as text.
line.qty = "2";
await screen.addLine({id: 7}, false, false, 1);
await screen.addLine(product, false, false, 1);
expect(line.qty).toBe(3);
});
});
Loading