diff --git a/addons/beyond_pos_theme/__manifest__.py b/addons/beyond_pos_theme/__manifest__.py index 134bcd9..c7de08b 100644 --- a/addons/beyond_pos_theme/__manifest__.py +++ b/addons/beyond_pos_theme/__manifest__.py @@ -25,6 +25,7 @@ El veredicto del spike está en docs/adr/ADR-001-spike-pos.md. 'assets': { 'point_of_sale._assets_pos': [ 'beyond_pos_theme/static/src/scss/beyond_pos.scss', + 'beyond_pos_theme/static/src/product_card/product_card.js', 'beyond_pos_theme/static/src/xml/product_card.xml', 'beyond_pos_theme/static/src/empleados_linea/empleados_linea.js', 'beyond_pos_theme/static/src/receipt/beyond_receipt.js', diff --git a/addons/beyond_pos_theme/static/src/product_card/product_card.js b/addons/beyond_pos_theme/static/src/product_card/product_card.js new file mode 100644 index 0000000..9117fc9 --- /dev/null +++ b/addons/beyond_pos_theme/static/src/product_card/product_card.js @@ -0,0 +1,33 @@ +/* Part of Beyond. Collina Systems proprietary module. */ +import { patch } from "@web/core/utils/patch"; +import { ProductCard } from "@point_of_sale/app/components/product_card/product_card"; + +/** + * Price shown on the product card (template in static/src/xml/product_card.xml). + * + * It used to print list_price, which was right while the whole network sold + * at one price. Since ADR-009 each branch prices from its own list, and the + * base price on the card would be a number the register never charges: the + * cashier reads 400 and the line rings up 450. This asks the POS for the + * same price the order will use. + * + * The pricelist is the order's when there is one open — a customer with a + * pricelist of their own changes it — and the register's default otherwise. + */ +patch(ProductCard.prototype, { + get beyondPrice() { + const template = this.props.product; + if (!template) { + return false; + } + const pos = this.env.services.pos; + const pricelist = pos?.getOrder()?.pricelist_id || pos?.config?.pricelist_id; + const variant = template.product_variant_ids?.[0]; + if (!pricelist || !variant || typeof template.getPrice !== "function") { + // Nothing to price against: fall back to the base price rather + // than leaving the card blank. + return template.list_price; + } + return template.getPrice(pricelist, 1, 0, false, variant); + }, +}); diff --git a/addons/beyond_pos_theme/static/src/xml/product_card.xml b/addons/beyond_pos_theme/static/src/xml/product_card.xml index e6c5baa..52f9825 100644 --- a/addons/beyond_pos_theme/static/src/xml/product_card.xml +++ b/addons/beyond_pos_theme/static/src/xml/product_card.xml @@ -3,17 +3,20 @@ - + t-esc="env.utils.formatCurrency(beyondPrice)"/> diff --git a/addons/beyond_pos_theme/tests/test_theme_assets.py b/addons/beyond_pos_theme/tests/test_theme_assets.py index b2cdb93..f3a2f1d 100644 --- a/addons/beyond_pos_theme/tests/test_theme_assets.py +++ b/addons/beyond_pos_theme/tests/test_theme_assets.py @@ -24,6 +24,22 @@ class TestBeyondPosThemeAssets(TransactionCase): with file_open(path) as handle: self.assertTrue(handle.read().strip(), f"{path} está vacío") + def test_la_tarjeta_no_pinta_el_precio_base(self): + """ADR-009: con lista de precios por sucursal, list_price en la + tarjeta es un número que la caja no cobra. El precio sale del getter + beyondPrice, que aplica la lista de la sucursal.""" + with file_open('beyond_pos_theme/static/src/xml/product_card.xml') as handle: + plantilla = handle.read() + self.assertIn('beyondPrice', plantilla) + self.assertNotIn('props.product.list_price', plantilla) + manifest = get_manifest('beyond_pos_theme') + bundle = manifest['assets'].get('point_of_sale._assets_pos', []) + self.assertIn( + 'beyond_pos_theme/static/src/product_card/product_card.js', bundle, + 'el getter tiene que viajar en el bundle del POS') + with file_open('beyond_pos_theme/static/src/product_card/product_card.js') as handle: + self.assertIn('getPrice', handle.read()) + def test_herencia_extiende_product_card(self): with file_open('beyond_pos_theme/static/src/xml/product_card.xml') as handle: contenido = handle.read()