printedparts stage 17: gage-lab asset tag + print-files redesign
The gage lab assigns real WJRP asset numbers, so identity splits: the internal itemcode stays auto-minted and a new optional unique gagelabtag (migration 0003) carries the lab's number - settable on create/edit, searchable, and resolved by the kiosk for scans and bare keypad digits against the numeric tail of either identifier (unique-match only). The print-files table becomes stacked revision cards - filename with rev/current badges, one meta line, delete pinned right - ending the horizontal scroll in that column.
This commit is contained in:
@@ -41,6 +41,7 @@ def list_items():
|
||||
like = f'%{search}%'
|
||||
query = query.filter(or_(
|
||||
PrintedItem.itemcode.ilike(like),
|
||||
PrintedItem.gagelabtag.ilike(like),
|
||||
PrintedItem.itemname.ilike(like),
|
||||
PrintedItem.itemdescription.ilike(like),
|
||||
PrintedItem.binlocation.ilike(like),
|
||||
@@ -103,18 +104,28 @@ def _mint_itemcode(item):
|
||||
@jwt_required()
|
||||
@require_permission('printedparts.create')
|
||||
def create_item():
|
||||
"""Create a printed item; the itemcode is minted from the row id."""
|
||||
"""Create a printed item.
|
||||
|
||||
The internal itemcode is always auto-minted; the OPTIONAL gagelabtag
|
||||
carries the gage lab's assigned WJRP asset number (unique-checked)."""
|
||||
data = request.get_json() or {}
|
||||
itemname = (data.get('itemname') or '').strip()
|
||||
if not itemname:
|
||||
return error_response(ErrorCodes.VALIDATION_ERROR, 'itemname is required')
|
||||
|
||||
gagelabtag = (data.get('gagelabtag') or '').strip().upper()
|
||||
if gagelabtag and PrintedItem.query.filter_by(gagelabtag=gagelabtag).first():
|
||||
return error_response(ErrorCodes.CONFLICT,
|
||||
f'Gage lab tag {gagelabtag} is already in use',
|
||||
http_code=409)
|
||||
|
||||
threshold = data.get('lowstockthreshold')
|
||||
if threshold is None:
|
||||
threshold = int(Setting.get('printedparts_default_threshold') or 5)
|
||||
|
||||
item = PrintedItem(
|
||||
itemname=itemname,
|
||||
gagelabtag=gagelabtag or None,
|
||||
itemdescription=data.get('itemdescription'),
|
||||
lowstockthreshold=threshold,
|
||||
binlocation=data.get('binlocation'),
|
||||
@@ -143,6 +154,18 @@ def update_item(item_id: int):
|
||||
return error_response(
|
||||
ErrorCodes.VALIDATION_ERROR,
|
||||
'quantityonhand is ledger-managed; use restock or adjust')
|
||||
if 'gagelabtag' in data:
|
||||
gagelabtag = (data.get('gagelabtag') or '').strip().upper()
|
||||
if gagelabtag:
|
||||
clash = PrintedItem.query.filter(
|
||||
PrintedItem.gagelabtag == gagelabtag,
|
||||
PrintedItem.printeditemid != item.printeditemid).first()
|
||||
if clash:
|
||||
return error_response(
|
||||
ErrorCodes.CONFLICT,
|
||||
f'Gage lab tag {gagelabtag} is already in use',
|
||||
http_code=409)
|
||||
item.gagelabtag = gagelabtag or None
|
||||
for field in EDITABLE_FIELDS:
|
||||
if field in data:
|
||||
setattr(item, field, data[field])
|
||||
@@ -391,16 +414,25 @@ def _kiosk_find_item(itemcode):
|
||||
|
||||
Accepts the full code (WJRP0042) or bare digits from the touch keypad
|
||||
(42 -> prefix + zero-pad), so manual entry never needs letters."""
|
||||
itemcode = (itemcode or '').strip()
|
||||
scanned = (itemcode or '').strip().upper()
|
||||
item = PrintedItem.query.filter(
|
||||
PrintedItem.itemcode == itemcode,
|
||||
or_(PrintedItem.itemcode == scanned,
|
||||
PrintedItem.gagelabtag == scanned),
|
||||
PrintedItem.isactive == True).first()
|
||||
if not item and itemcode.isdigit():
|
||||
# The digits in a minted code ARE the row id, so id lookup keeps
|
||||
# working even for labels printed under an older prefix.
|
||||
candidate = db.session.get(PrintedItem, int(itemcode))
|
||||
if candidate and candidate.isactive:
|
||||
item = candidate
|
||||
if not item and scanned.isdigit():
|
||||
# Bare digits from the touch keypad match the NUMBER inside either
|
||||
# identifier (internal code or gage-lab tag). Small catalog: scan
|
||||
# actives and compare numeric tails; only a UNIQUE match counts.
|
||||
wanted = int(scanned)
|
||||
matches = []
|
||||
for candidate in PrintedItem.query.filter_by(isactive=True).all():
|
||||
for value in (candidate.itemcode, candidate.gagelabtag):
|
||||
tail = ''.join(ch for ch in (value or '') if ch.isdigit())
|
||||
if tail and int(tail) == wanted:
|
||||
matches.append(candidate)
|
||||
break
|
||||
if len(matches) == 1:
|
||||
item = matches[0]
|
||||
return item
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user