fix: POST /products 500 — invalid unit FK on unrecognized items
Two bugs caused a FK constraint violation on products.unit: 1. RecognizedItem.fromJson fell back to 'шт' (Cyrillic, not a valid units.code) when the AI returned a null unit — changed to 'pcs'. 2. The unit dropdown in RecognitionConfirmScreen displayed units.keys.first for invalid units but never updated item.unit, so the invalid value was still submitted. Added a reconcile step in build() that syncs item.unit to units.keys.first whenever the stored value is not in the valid set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -39,7 +39,7 @@ class RecognizedItem {
|
||||
return RecognizedItem(
|
||||
name: json['name'] as String? ?? '',
|
||||
quantity: (json['quantity'] as num?)?.toDouble() ?? 1.0,
|
||||
unit: json['unit'] as String? ?? 'шт',
|
||||
unit: json['unit'] as String? ?? 'pcs',
|
||||
category: json['category'] as String? ?? 'other',
|
||||
confidence: (json['confidence'] as num?)?.toDouble() ?? 0.0,
|
||||
mappingId: json['mapping_id'] as String?,
|
||||
|
||||
Reference in New Issue
Block a user