Stock: items.trackStock, so an empty stock really means unlimited

PocketBase 0.23 can't store an empty number (it reads back as 0), so a
product saved with "Unlimited when empty" stock was sold out — on main
too. trackStock says whether stock counts; existing products get it on,
so nothing that sells today changes. The shop maps untracked stock to
null (unlimited), as the UI always assumed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hy2vMnHJYP7QGsiH21zHxW
This commit is contained in:
agent 2026-10-25 21:39:51 +00:00
parent e30e1d3beb
commit 32984ac01d
4 changed files with 35 additions and 8 deletions

View file

@ -490,7 +490,7 @@ function normaliseCode(value) {
.replace(/[^A-Z0-9]/g, '');
}
/** `ABCD2345` → `ABCD-2345`, as shown to people. */
/** `ABCD2345` → `ABCD-2345`, as shown to people (formatCode in packages/shared/src/items.ts does the same). */
function formatCode(code) {
return code.length === CODE_LENGTH ? code.slice(0, 4) + '-' + code.slice(4) : code;
}
@ -628,8 +628,7 @@ function stockProblem(app, needs) {
for (const id of Object.keys(needs)) {
const item = findOrNull(app, 'items', id);
if (!item) continue;
const stock = item.get('stock');
if (stock != null && stock !== '' && needs[id] > item.getInt('stock')) {
if (item.getBool('trackStock') && needs[id] > item.getInt('stock')) {
return conflict(item.getInt('stock') > 0 ? `Only ${item.getInt('stock')} of "${item.getString('name')}" left in stock` : `"${item.getString('name')}" is sold out`);
}
}
@ -1176,7 +1175,7 @@ function createOrderFromIntent(app, intent) {
}
function takeStock(app, item, quantity) {
if (!item || item.get('stock') == null || item.get('stock') === '') return;
if (!item || !item.getBool('trackStock')) return;
item.set('stock', Math.max(0, item.getInt('stock') - quantity));
app.save(item);
}