Productos: allowed_order_units + fix sync que pisaba overrides

Introduce un campo nuevo allowed_order_units por producto (array kg/unit)
que separa "cómo se vende" de "cómo se puede pedir". Productos sell_unit=unit
solo aceptan unit (regla dura aplicada por código y handler). Productos
sell_unit=kg defaultean a ambos, editable desde la UI con checkboxes.

Fixea bug crítico de wooSnapshot.upsertSnapshotItems que pisaba raw entero
en cada sync, perdiendo overrides locales (_sell_unit_override,
_categories_override y el nuevo _allowed_order_units). El UPDATE ahora
mergea preservando los overrides.

Las tools del agente (addToCart, setQuantity, selectCandidate) validan
unit contra allowed_order_units y devuelven unit_not_allowed para que el
LLM re-pregunte. workingMemory expone allowed_order_units y needs_unit_choice.
buildLineItems agrega meta_data unit/sell_unit_product/unit_mode_mismatch
y omite subtotal/total cuando hay mismatch para que Woo recalcule.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lucas Tettamanti
2026-05-18 00:40:12 -03:00
parent c786e47160
commit 423a99ab48
18 changed files with 431 additions and 72 deletions

View File

@@ -116,12 +116,12 @@ export const api = {
}).then(r => r.json());
},
async updateProduct(wooProductId, { sell_unit, categories }) {
return fetch(`/products/${encodeURIComponent(wooProductId)}`, {
async updateProduct(wooProductId, { sell_unit, categories, allowed_order_units }) {
return safeFetch(`/products/${encodeURIComponent(wooProductId)}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ sell_unit, categories }),
}).then(r => r.json());
body: JSON.stringify({ sell_unit, categories, allowed_order_units }),
});
},
async updateProductsUnit(wooProductIds, { sell_unit }) {