feat: each product's metres are summed and rounded once, and the 1 m minimum is once per order (Marcus, 2026-12-03)
All checks were successful
Build and deploy / Validate source (push) Successful in 5s
Build and deploy / Integration suite on a real stack (push) Successful in 8m24s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m14s

Marcus: "o pedido mínimo de um metro deve ser somente para o primeiro
metro, após isso deve se somar a metragem de cada arquivo", "Soma tudo e
arredonda uma vez só", and for different products "Pode ser sim": each
product apart at its price, the minimum for the whole order. Order #246
(three ready sheets of 3,74, 0,24 and 0,22 m) was 5,80 m with 1 m per item;
it is now 4,20 m.

pricing.bill_order replaces the per-item minimum and bill_splits: per
product the exact lengths (a ready sheet without its gaps) are rounded once
with the 8 mm grace, the minimum's difference goes to the first item's
product, and each product's total is shared back to its items in 10 cm
steps (each its length rounded down, the missing steps to the largest
fractions, the minimum to the product's first item), for Tiny's 10 cm SKUs
and the cards. A share of 0 m adds no Tiny line. The print file's guard
allows an item one 10 cm step under its length. The Site cart shares the
same way (cobrarPedido), split sheets round once, the buy box says the
items of a product are summed and rounded once, and the Montador's
estimate rounds its sum once. Contract: output/revisao/contrato-minimo-pedido.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-12-03 12:46:40 -03:00
parent 911892351f
commit 083441583a
13 changed files with 145 additions and 20 deletions

View File

@@ -154,16 +154,20 @@ function montarQuoteFigures(lines){
});
const catalog=MONTAR.catalog?.avulsa;
if(!catalog)throw new Error('Preço de tabela indisponível agora.');
// Every 10 cm, 8 mm in the customer's favour (app/core/pricing.py billed_length).
const billed=heights.map(metres=>Math.max(1,Math.ceil(+((metres-0.008)*10).toFixed(6))/10));
const total=+billed.reduce((sum,metres)=>sum+metres,0).toFixed(2);
// The items' lengths summed and rounded once, every 10 cm with 8 mm in the
// customer's favour, and the 1 m minimum once for the order (Marcus,
// 2026-12-03; app/core/pricing.py bill_order). One product here: avulsa.
const exact=+heights.reduce((sum,metres)=>sum+metres,0).toFixed(6);
const total=heights.length?Math.max(1,Math.ceil(+((exact-0.008)*10).toFixed(6))/10):0;
let unit=catalog.unit_cents,best=null;
for(const band of catalog.bands||[]){
const from=Number(band.from_metres);
if(total>=from&&(best===null||from>=best)){best=from;unit=band.unit_cents;}
}
return {metres:+heights.reduce((sum,metres)=>sum+metres,0).toFixed(4),
cents:billed.reduce((sum,metres)=>sum+Math.floor(Number((metres*unit).toFixed(6))),0)};
// The shares of the total cost the total at one unit price, to the cent
// the server's per-item truncation may differ by: an estimate for freight.
cents:Math.floor(Number((total*unit).toFixed(6)))};
}
async function montarCatalog(){
if(MONTAR.catalog)return MONTAR.catalog;