diff --git a/app/core/pricing.py b/app/core/pricing.py index d0aad0e..41cfb98 100644 --- a/app/core/pricing.py +++ b/app/core/pricing.py @@ -8,6 +8,19 @@ import os import re from decimal import Decimal, ROUND_CEILING +# Billed in steps of 10 cm, with 8 mm of grace for the customer (Marcus, +# 2026-11-27): a length that passes a step by up to 8 mm is billed at that +# step, by more at the next one. The Site rounds the same (web/site-config.js). +STEP_GRACE_M = Decimal('0.008') + + +def billed_length(length): + """The metres billed for `length` metres, before any minimum; never 0 for + a sheet that has a length.""" + steps = ((Decimal(str(length)) - STEP_GRACE_M) * 10).to_integral_value(rounding=ROUND_CEILING) + return max(Decimal('0.1'), steps / 10) + + PRICES = {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990, 'premium': 3990} # A finished sheet the Site cannot open (CDR, AI, PSD, TIFF) is opened by a @@ -55,7 +68,7 @@ def price(mode: str, metres: str, grade: int, extra_cents: int = 0, minimum: Dec raise ValueError('Invalid product or length') if isinstance(grade, bool) or not isinstance(grade, int) or not 0 <= grade <= 100: raise ValueError('Grade must be an integer between 0 and 100') - billed = max(minimum, (length * 10).to_integral_value(rounding=ROUND_CEILING) / 10) + billed = max(minimum, billed_length(length)) if isinstance(extra_cents, bool) or not isinstance(extra_cents, int) or extra_cents < 0: raise ValueError('Invalid extra charge') unit = (PRICES[mode] if unit_cents is None else unit_cents) + extra_cents diff --git a/app/printfile.py b/app/printfile.py index 62b3e5d..98a89b5 100644 --- a/app/printfile.py +++ b/app/printfile.py @@ -27,6 +27,7 @@ from decimal import Decimal from PIL import Image, ImageOps from .core.models import PRODUCTION_VERSIONS +from .core.pricing import STEP_GRACE_M PT_PER_CM = 72 / 2.54 # Acrobat's page limit, 200 inches (5,08 m). A longer sheet is written at its @@ -387,7 +388,8 @@ def check_layout(item, sizes, vector=(), proof=False): production = item['production'] height = Decimal(str(production['height_cm'])) billed = Decimal(str(item['billed_metres'])) * 100 - if not proof and height > billed + HEIGHT_TOLERANCE_CM: + # Up to 8 mm past the billed length is the customer's grace (app/core/pricing.py). + if not proof and height > billed + STEP_GRACE_M * 100 + HEIGHT_TOLERANCE_CM: raise Unsupported(f'a montagem tem {height} cm, mas só {billed} cm foram cobrados') lowest = None for placement in production['placements']: diff --git a/tests/test_cart_pricing.py b/tests/test_cart_pricing.py index 033dd74..ca6cb7e 100644 --- a/tests/test_cart_pricing.py +++ b/tests/test_cart_pricing.py @@ -165,8 +165,10 @@ class CartPricingCharacterizationTest(unittest.TestCase): split = priced('split-under-one-metre') self.assertEqual([(p['billed_metres'], p['total_cents']) for p in split], [('0.8', 1752), ('0.2', 438)]) + # A float's noise past 2,80 m is inside the 8 mm grace (Marcus, + # 2026-11-27): billed 2,80 m at the band from 2,8 m, no longer 2,90 m. floating = priced('band-floating-metres')[0] - self.assertEqual((floating['billed_metres'], floating['total_cents']), ('2.9', 24650)) + self.assertEqual((floating['billed_metres'], floating['total_cents']), ('2.8', 23800)) def test_ajuste_fino_is_per_art_with_the_band(self): # Front 1a: 1 to 9 arts at R$ 9,90, from 10 at R$ 6,90, all arts charged diff --git a/tests/test_pricing.py b/tests/test_pricing.py index e74780e..70667a6 100644 --- a/tests/test_pricing.py +++ b/tests/test_pricing.py @@ -16,9 +16,14 @@ class PricingTests(unittest.TestCase): source = Path('web/site-config.js').read_text() prices = source.split('const PRECO=')[1].split(';',1)[0] calculator = source.split('const cobrar=')[1].split(';',1)[0] - js = f'const PRECO={prices};const MINIMO_M=1;const cobrar={calculator};' + # Every 10 cm with 8 mm of grace (Marcus, 2026-11-27): the Site's own rounding. + grace = source.split('const TOLERANCIA_M=')[1].split(';',1)[0] + rounding = source.split('const arredonda10=')[1].split(';',1)[0] + js = (f'const PRECO={prices};const MINIMO_M=1;const TOLERANCIA_M={grace};' + f'const arredonda10={rounding};const cobrar={calculator};') js += '''const results=[];for(const mode of Object.keys(PRECO)) - for(const metres of [0.01,0.99,1,1.01,1.1,2.75,2.8,2.8000000000000003,19.99,60,12000]){ + for(const metres of [0.01,0.99,1,1.01,1.1,2.75,2.8,2.8000000000000003,19.99,60,12000, + 1.008,1.0081,4.452,6.001,6.008,6.0081,6.009,5.992]){ const unit=PRECO[mode]; results.push([mode,String(metres),cobrar(metres),Math.round(unit*100),Math.round(cobrar(metres)*unit*100)]); }process.stdout.write(JSON.stringify(results));''' @@ -32,6 +37,18 @@ class PricingTests(unittest.TestCase): self.assertEqual(result['unit_cents'],unit) self.assertEqual(result['total_cents'],total) + def test_every_10_cm_with_8_mm_in_the_customers_favour(self): + # Marcus, 2026-11-27: up to 8 mm past a step stays in it, more goes on. + from app.core.pricing import billed_length + for metres, billed in (('6.001', '6'), ('6.008', '6'), ('6.0081', '6.1'), ('6.009', '6.1'), + ('4.452', '4.5'), ('4.42', '4.5'), ('2.75', '2.8'), ('0.005', '0.1')): + with self.subTest(metres=metres): + self.assertEqual(billed_length(metres), Decimal(billed)) + # Marcus's two examples: 3 copies of ~199,5 cm with 8 mm between them, + # and 5 copies of 88,4 cm. + self.assertEqual(price('file', '6.001', 100)['billed_metres'], '6') + self.assertEqual(price('file', '4.452', 100)['billed_metres'], '4.5') + def test_one_price_per_product(self): # Dropstar, 2026-10-23: textile R$ 19,90 ready sheet and R$ 21,90 loose # art; UV R$ 79,90 and R$ 89,90. Premium R$ 39,90 (2026-11-10). diff --git a/web/kanban-montador.js b/web/kanban-montador.js index 3234b74..46e5ded 100644 --- a/web/kanban-montador.js +++ b/web/kanban-montador.js @@ -154,7 +154,8 @@ function montarQuoteFigures(lines){ }); const catalog=MONTAR.catalog?.avulsa; if(!catalog)throw new Error('Preço de tabela indisponível agora.'); - const billed=heights.map(metres=>Math.max(1,Math.ceil(metres*10)/10)); + // 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); let unit=catalog.unit_cents,best=null; for(const band of catalog.bands||[]){ diff --git a/web/site-compra.js b/web/site-compra.js index 892a0d8..3d0fbaa 100644 --- a/web/site-compra.js +++ b/web/site-compra.js @@ -12,13 +12,24 @@ $('cMetroLbl').textContent = it.extra ? 'Metro · com '+rs(it.extra)+' de arquivo manual' : 'Metro'; $('cMetro').textContent=rs(it.unit); $('cMetragem').textContent=fmtM(it.cob)+' m'; - const partes=ehFolha(it.modo) ? Math.ceil(it.metros/20) : 1; - $('cPartes').textContent = partes>1 ? ' Sai em '+partes+' partes de até 20 m.' : ''; + // Partes de até 10 m (Marcus, 18/11/2026): o FlexiPRINT não abre mais que isso. + const partes=ehFolha(it.modo) ? Math.ceil(it.metros/10) : 1; + $('cPartes').textContent = partes>1 ? ' Sai em '+partes+' partes de até 10 m.' : ''; const sobraCm=Math.round((it.cob-it.metros)*100); + // A metragem cobrada explicada como vantagem (Marcus, 27/11/2026): a cada + // 10 cm, e até 8 mm a mais ficam por nossa conta. + const exata=n1(it.metros*100)+' cm'; + const aMais=Math.round((it.metros-it.cob)*1000); $('cObs').textContent = it.cob===MINIMO_M && it.metros1?'os '+aMais+' mm a mais ficam':aMais===1?'o 1 mm a mais fica':'o que passou fica')+' por nossa conta.' + : it.cob>it.metros+1e-6 + ? 'A folha tem '+exata+'. Cobramos a cada 10 cm, então fica '+fmtM(it.cob)+' m. '+ + 'Se passar até 8 mm de uma faixa, esse pedaço fica por nossa conta.' : ''; $('cTotal').textContent=rs(it.total); } diff --git a/web/site-config.js b/web/site-config.js index 9f09891..cdb66a2 100644 --- a/web/site-config.js +++ b/web/site-config.js @@ -206,11 +206,16 @@ function faltaLeitura(l){ return s<10 ? 'faltam '+Math.max(1,Math.ceil(s))+' s' : s<60 ? 'faltam cerca de '+Math.ceil(s/5)*5+' s' : 'faltam cerca de '+duracao(s); } const larguraFilme=()=>MODOS[modo].larg; -// cobrança proporcional: arredonda para cima em 10 cm · 2,75 m vira 2,80 m -const cobrar=m=>Math.max(MINIMO_M, Math.ceil(m*10)/10); +// Cobrança a cada 10 cm, com 8 mm a favor do cliente (Marcus, 27/11/2026): +// passou até 8 mm de um múltiplo de 10 cm, fica nele; passou mais, vai para o +// próximo. 2,75 m vira 2,80 m; 6,005 m fica 6,00 m. A mesma regra do servidor +// (app/core/pricing.py billed_length). +const TOLERANCIA_M=0.008; +const arredonda10=m=>Math.max(0.1, Math.ceil(+((m-TOLERANCIA_M)*10).toFixed(6))/10); +const cobrar=m=>Math.max(MINIMO_M, arredonda10(m)); // Com as artes em folhas separadas por traço (item 17), cada folha arredonda // a 10 cm e o mínimo de 1 m vale para a soma: o cliente não escolheu separar. -const cobrarFolhas=fs=>Math.max(MINIMO_M, +fs.reduce((t,f)=>t+Math.ceil(+(f.alturaCm/100).toFixed(4)*10)/10,0).toFixed(1)); +const cobrarFolhas=fs=>Math.max(MINIMO_M, +fs.reduce((t,f)=>t+arredonda10(+(f.alturaCm/100).toFixed(4)),0).toFixed(1)); const cobrarMontagem=()=>!ehFolha() && montagemFolhas ? cobrarFolhas(montagemFolhas) : cobrar(metros); const fmtM=m=>m.toFixed(2).replace('.',','); const cls=n=>n>=85?'ok':n>=50?'av':'er'; diff --git a/web/site-packing.js b/web/site-packing.js index 0a7faad..0fb59ab 100644 --- a/web/site-packing.js +++ b/web/site-packing.js @@ -257,7 +257,7 @@ function montaFolhasDeTraco(grupos,W){ figura.append(legenda,desenho); painel.append(figura); desenhaMontagem(desenho, lista, 0, W, uso, r=>{ if(area.montagemVersao!==versao) return; // a montagem mudou nesse meio-tempo - legenda.textContent='Folha '+(i+1)+' · '+NOMES_TRACO[i]+' · '+fmtM(Math.ceil(+(r.alturaCm/100).toFixed(4)*10)/10)+' m'; + legenda.textContent='Folha '+(i+1)+' · '+NOMES_TRACO[i]+' · '+fmtM(arredonda10(+(r.alturaCm/100).toFixed(4)))+' m'; feitas[i]={nome:NOMES_TRACO[i], artes:lista, alturaCm:r.alturaCm, folgaCm:r.folgaCm ?? MARGEM_CM, layout:r.placements ? {height_cm:+r.alturaCm.toFixed(4), placements:r.placements} : null}; if(feitas.filter(Boolean).length'+ ''+ ''+ - '
'+(x.rep>1? x.rep+' × '+fmtM(x.m)+' m = ' : '')+''+fmtM(sub)+' m
' : '')+ + // A conta inteira, como é cobrada: o comprimento exato do arquivo e os + // 8 mm entre as cópias (Marcus, 27/11/2026: "falta explicar melhor"). + '
'+(x.rep>1 + ? x.rep+' × '+n1(x.m*100)+' cm + '+(x.rep-1)+(x.rep>2?' espaços':' espaço')+' de 8 mm = '+ + n1(sub*100+(x.rep-1)*MARGEM_FOLHA_CM)+' cm' + : ''+n1(x.m*100)+' cm')+'
' : '')+ '' : ''; return '
'+ '
'+mini+'
'+