/** @odoo-module * * Pricing hook (PREPARE-ONLY). * * Reads the per-type and per-attribute extra_price values for the * current order. Returned values are NEVER applied to the order. * This module exists so future pricing logic can plug into a single * stable surface without touching order.lines / pricing / taxes today. * * Usage example (NOT wired anywhere): * import { computeLaundryExtras } from "@laundry_management/js/laundry_pricing_hook"; * const { typeExtra, attributeExtras, total } = computeLaundryExtras(pos, order); */ export function computeLaundryExtras(pos, order) { const empty = { typeExtra: 0, attributeExtras: [], total: 0 }; if (!pos || !order) return empty; const typeId = order.laundry_order_type_id; const attrIds = Array.isArray(order.laundry_order_attribute_ids) ? order.laundry_order_attribute_ids : []; let typeExtra = 0; if (typeId) { const type = pos.models["laundry.order.type"]?.get(typeId); typeExtra = Number(type?.extra_price) || 0; } const attrModel = pos.models["laundry.order.attribute"]; const attributeExtras = []; let attrTotal = 0; for (const id of attrIds) { const rec = attrModel?.get(id); const price = Number(rec?.extra_price) || 0; if (price) { attributeExtras.push({ id, name: rec?.name || "", price }); attrTotal += price; } } return { typeExtra, attributeExtras, total: typeExtra + attrTotal, }; }