correjido unidades y kgs

This commit is contained in:
Lucas Tettamanti
2026-01-25 21:08:23 -03:00
parent bb947ea75e
commit 93e331535f
2 changed files with 5 additions and 2 deletions

View File

@@ -746,7 +746,8 @@ function createPendingItemFromSearch({ query, quantity, unit, candidates }) {
(best?._score >= 0.9 && (!second || best._score - (second?._score || 0) >= 0.2));
if (isStrong) {
const displayUnit = inferDefaultUnit({ name: best.name, categories: best.categories });
// Usar sell_unit del producto si está configurado, sino inferir por heurística
const displayUnit = normalizeUnit(best.sell_unit) || inferDefaultUnit({ name: best.name, categories: best.categories });
const hasQty = quantity != null && Number.isFinite(Number(quantity)) && Number(quantity) > 0;
const sellsByWeight = displayUnit !== "unit";
const hasExplicitUnit = unit != null && unit !== "";
@@ -773,7 +774,8 @@ function createPendingItemFromSearch({ query, quantity, unit, candidates }) {
woo_id: c.woo_product_id,
name: c.name,
price: c.price,
display_unit: inferDefaultUnit({ name: c.name, categories: c.categories }),
sell_unit: c.sell_unit || null,
display_unit: normalizeUnit(c.sell_unit) || inferDefaultUnit({ name: c.name, categories: c.categories }),
})),
status: PendingStatus.NEEDS_TYPE,
});