From 911892351fb1d866084a41dea96a776235d093f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Thu, 3 Dec 2026 11:24:13 -0300 Subject: [PATCH] feat: the 8 mm between a ready sheet's copies stay on the film but are no longer billed (Marcus, 2026-12-03) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Marcus on 26/11 had the gaps count in the billed metres; on 2026-12-03, after customers of Lais and Kedma refused orders billed 10 and 20 cm more, "por hora pode tirar a cobrança". A ready sheet is now billed on the sum of its sheets and copies (pricing.billable_metres: the layout's height less unbilled_gaps_cm, at most 8 mm between each two pieces); `metres` stays the film laid out, which the print file, the parts and the folders follow, and the print file's billed-length guard allows the gap film. Loose art keeps its packing. The Site bills folhaCobradaM, the copies line reads "5 × 45,9 cm = 229,3 cm" and the buy box explains that length. The Lais case, 5 sheets of 100 cm, bills 5,00 m instead of 5,10 m. Co-Authored-By: Claude Opus 5.5 --- app/cart_pricing.py | 9 ++++++--- app/core/pricing.py | 25 +++++++++++++++++++++++++ app/printfile.py | 8 +++++--- tests/test_cart_pricing.py | 18 ++++++++++++++++++ tests/test_sheet_gap.py | 14 ++++++++++++++ web/site-cart.js | 2 ++ web/site-compra.js | 14 ++++++++------ web/site-config.js | 11 ++++++++--- web/site-packing.js | 2 +- web/site-pdf.js | 9 ++++----- 10 files changed, 91 insertions(+), 21 deletions(-) diff --git a/app/cart_pricing.py b/app/cart_pricing.py index 1bcc8a3..cb0d46e 100644 --- a/app/cart_pricing.py +++ b/app/cart_pricing.py @@ -80,9 +80,12 @@ def price_items(items, names, catalog_now, manual_extra): for item in items: extra = manual_extra if pricing.is_manual(item, names) else 0 product = catalog_now[item['mode']] - priced.append({**pricing.price(item['mode'], str(item['metres']), item['grade'], extra, - minimum=Decimal('0') if item.get('split') else Decimal('1'), - unit_cents=product['unit_cents']), + # Billed on the length less a ready sheet's gaps; `metres` stays the + # film the layout uses, which the print file and the folders follow. + charged = pricing.price(item['mode'], str(pricing.billable_metres(item)), item['grade'], extra, + minimum=Decimal('0') if item.get('split') else Decimal('1'), + unit_cents=product['unit_cents']) + priced.append({**charged, 'metres': str(item['metres']), **({'split': item['split']} if item.get('split') else {})}) pricing.bill_splits(priced) totals = {} diff --git a/app/core/pricing.py b/app/core/pricing.py index 41cfb98..49170c9 100644 --- a/app/core/pricing.py +++ b/app/core/pricing.py @@ -12,6 +12,31 @@ from decimal import Decimal, ROUND_CEILING # 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') +# The film between a ready sheet's copies (app/core/models.py SHEET_GAP_CM). +SHEET_GAP_CM = Decimal('0.8') + + +def unbilled_gaps_cm(production): + """The film between a ready sheet's copies and sheets (8 mm each, Marcus + 26/11): laid out, but not billed since Marcus's 2026-12-03 answer ("por + hora pode tirar a cobrança"). The layout's height less its pieces; zero + for loose art, whose spacing is part of the packing.""" + production = production or {} + sources = production.get('sources') or [] + if not sources or any(source.get('kind') != 'sheet' for source in sources): + return Decimal('0') + placements = production.get('placements') or [] + if len(placements) < 2: + return Decimal('0') + pieces = sum(Decimal(str(p['length_cm'])) for p in placements) + # Never more than one gap of SHEET_GAP_CM between each two pieces. + most = SHEET_GAP_CM * (len(placements) - 1) + return min(most, max(Decimal('0'), Decimal(str(production['height_cm'])) - pieces)) + + +def billable_metres(item): + """The metres an item is billed on: its length less the unbilled gaps.""" + return Decimal(str(item['metres'])) - unbilled_gaps_cm(item.get('production')) / 100 def billed_length(length): diff --git a/app/printfile.py b/app/printfile.py index 98a89b5..e672804 100644 --- a/app/printfile.py +++ b/app/printfile.py @@ -27,7 +27,7 @@ from decimal import Decimal from PIL import Image, ImageOps from .core.models import PRODUCTION_VERSIONS -from .core.pricing import STEP_GRACE_M +from .core.pricing import STEP_GRACE_M, unbilled_gaps_cm PT_PER_CM = 72 / 2.54 # Acrobat's page limit, 200 inches (5,08 m). A longer sheet is written at its @@ -388,8 +388,10 @@ def check_layout(item, sizes, vector=(), proof=False): production = item['production'] height = Decimal(str(production['height_cm'])) billed = Decimal(str(item['billed_metres'])) * 100 - # 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: + # Up to 8 mm past the billed length is the customer's grace, and a ready + # sheet's gaps are film not billed (app/core/pricing.py). + allowed = billed + STEP_GRACE_M * 100 + unbilled_gaps_cm(production) + HEIGHT_TOLERANCE_CM + if not proof and height > allowed: 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 ca6cb7e..3231ac3 100644 --- a/tests/test_cart_pricing.py +++ b/tests/test_cart_pricing.py @@ -170,6 +170,24 @@ class CartPricingCharacterizationTest(unittest.TestCase): floating = priced('band-floating-metres')[0] self.assertEqual((floating['billed_metres'], floating['total_cents']), ('2.8', 23800)) + def test_a_ready_sheet_is_billed_without_its_gaps(self): + # Marcus, 2026-12-03 ("por hora pode tirar a cobrança"): the Lais case, + # one 100 cm sheet and another with 4 copies, 4 gaps of 8 mm = 503,2 cm. + sheet = item('file', '5.032') + sheet['production']['placements'] = [ + {'source_index': 0, 'copy_index': i, 'x_cm': 0, 'y_cm': i * 100.8, 'width_cm': 57, + 'length_cm': 100, 'rotation_degrees': 0, 'mirrored': False} for i in range(5)] + priced = price_items([sheet], {}, catalog_now(), 0)[0] + self.assertEqual(priced['billed_metres'], '5') + self.assertEqual(priced['total_cents'], 9950) + self.assertEqual(priced['metres'], '5.032') # the film stays as laid out + self.assertEqual(pricing.unbilled_gaps_cm(sheet['production']), Decimal('3.2')) + # Loose art keeps its packing; one piece has no gap. + loose = item('avulsa', '1.5') + loose['production']['placements'] = sheet['production']['placements'] + self.assertEqual(pricing.unbilled_gaps_cm(loose['production']), 0) + self.assertEqual(pricing.unbilled_gaps_cm(item('file', '1')['production']), 0) + 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 # at the band. `true` keeps meaning every art of the cart. diff --git a/tests/test_sheet_gap.py b/tests/test_sheet_gap.py index 4aa31d3..225bba4 100644 --- a/tests/test_sheet_gap.py +++ b/tests/test_sheet_gap.py @@ -27,6 +27,20 @@ def sheet(copies=3, gap=0.8, mode='file'): class SheetGapTests(unittest.TestCase): + def test_the_print_file_takes_the_unbilled_gaps(self): + # Marcus, 2026-12-03: the gaps stay on the film but are not billed, so + # 10 copies of 20 cm (200 cm billed, 207,2 cm laid out) still print. + try: + from app.printfile import Unsupported, check_layout + except ImportError: # the host job has no imaging libraries + self.skipTest('app.printfile needs the runtime image') + item = sheet(copies=10).model_dump(mode='json') + item['billed_metres'] = '2' + check_layout(item, [(5700, 2000)]) + item['billed_metres'] = '1.9' + with self.assertRaises(Unsupported): + check_layout(item, [(5700, 2000)]) + def test_copies_8_mm_apart_pass(self): check_sheet_gaps([sheet()]) check_sheet_gaps([sheet(copies=1, gap=0)]) diff --git a/web/site-cart.js b/web/site-cart.js index 2511dbf..2eabafc 100644 --- a/web/site-cart.js +++ b/web/site-cart.js @@ -414,6 +414,8 @@ function carrinho(){ layout=montagemLayout; } itemAtual={modo, tit:MODOS[modo].tit, nota, metros, cob, unit, extra, total:tot, + // What is billed: a ready sheet without its gaps (Marcus, 03/12/2026). + cobravel:ehFolha()?+folhaCobradaM().toFixed(4):metros, localFiles:(ehFolha()?folhas:artes).map(x=>x.f), mini:(ehFolha()?folhas:artes).map(x=>x.miniSrc).find(Boolean)||null, fotos:(ehFolha()?folhas:artes).map(x=>x.fotoSrc||null), diff --git a/web/site-compra.js b/web/site-compra.js index fce2ce8..3ac0c3e 100644 --- a/web/site-compra.js +++ b/web/site-compra.js @@ -58,19 +58,21 @@ // 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 ready sheet is billed without the gaps between its copies (03/12/2026). + const base=it.cobravel??it.metros; + const sobraCm=Math.round((it.cob-base)*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); + const exata=n1(base*100)+' cm'; + const aMais=Math.round((base-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 + : it.cob>base+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.' : ''; diff --git a/web/site-config.js b/web/site-config.js index 71e0003..5751851 100644 --- a/web/site-config.js +++ b/web/site-config.js @@ -132,11 +132,15 @@ let CLIENTE='SEU NOME AQUI', PEDIDO='000000'; let modo=null, artes=[], recemChegada=null, metros=0, nota=0, reencaixado=false; let folhas=[]; // [{f, med, rep, m}] · o cliente pode subir várias // Entre uma cópia e outra da folha pronta, e entre uma folha e outra, 8 mm de -// filme limpo para o recorte; entram na metragem cobrada (Marcus, 26/11/2026). +// filme limpo para o recorte (Marcus, 26/11/2026). Ficam na montagem, mas não +// são cobrados (Marcus, 03/12/2026: "por hora pode tirar a cobrança"): a +// metragem cobrada é a soma das folhas e cópias (app/core/pricing.py +// billable_metres). const MARGEM_FOLHA_CM=0.8; +const folhaCobradaM=()=>folhas.reduce((t,x)=>t+(x.m||0)*(x.rep||1),0); const folhaTotalM=()=>{ const copias=folhas.reduce((t,x)=>t+(x.m>0?(x.rep||1):0),0); - return folhas.reduce((t,x)=>t+(x.m||0)*(x.rep||1),0)+Math.max(0,copias-1)*MARGEM_FOLHA_CM/100; + return folhaCobradaM()+Math.max(0,copias-1)*MARGEM_FOLHA_CM/100; }; // O cliente declara o que está mandando escolhendo o produto, em vez de o site // adivinhar pelo formato do arquivo. A declaração de folha montada é conferida na @@ -225,7 +229,8 @@ 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+arredonda10(+(f.alturaCm/100).toFixed(4)),0).toFixed(1)); -const cobrarMontagem=()=>!ehFolha() && montagemFolhas ? cobrarFolhas(montagemFolhas) : cobrar(metros); +const cobrarMontagem=()=>ehFolha() ? cobrar(folhaCobradaM()) + : montagemFolhas ? cobrarFolhas(montagemFolhas) : cobrar(metros); const fmtM=m=>m.toFixed(2).replace('.',','); const cls=n=>n>=85?'ok':n>=50?'av':'er'; const dpiDe=a=>a.cm>0? (a.giro?a.py:a.px)/(a.cm/2.54) : 0; diff --git a/web/site-packing.js b/web/site-packing.js index 8633f78..de0b3ab 100644 --- a/web/site-packing.js +++ b/web/site-packing.js @@ -276,7 +276,7 @@ function previaAoVivo(){ if(!ehFolha()) $('bAmpliar').hidden=true; if(ehFolha()){ $('vUso').innerHTML=''; - const tot=folhaTotalM(); + const tot=folhaCobradaM(); $('vMt').textContent = tot>0 ? fmtM(cobrar(tot))+' m' : '—'; const medidas=folhas.filter(x=>x.med); // Sheets still being read show a placeholder; a sheet printed N times is diff --git a/web/site-pdf.js b/web/site-pdf.js index 25dbe4b..88cb5d2 100644 --- a/web/site-pdf.js +++ b/web/site-pdf.js @@ -597,7 +597,7 @@ function pintaFolha(){ $('zona').classList.toggle('compacta', folhas.length>0); if(!folhas.length){ $('lista').innerHTML=''; agendaAvaliacao(); previaAoVivo(); agendaEnvios(); return; } - const tot=folhaTotalM(); + const tot=folhaCobradaM(); // the metres billed, without the gaps $('lista').innerHTML = '

Seus arquivos

'+ folhas.length+' folha'+(folhas.length>1?'s':'')+(tot>0? ' · '+fmtM(tot)+' m' : '')+'
'+ folhas.map((x,i)=>{ @@ -663,11 +663,10 @@ function pintaFolha(){ ''+ ''+ ''+ - // 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"). + // A conta como é cobrada: o comprimento exato do arquivo vezes as + // cópias; os 8 mm entre elas não entram (Marcus, 03/12/2026). '
'+(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' + ? x.rep+' × '+n1(x.m*100)+' cm = '+n1(sub*100)+' cm' : ''+n1(x.m*100)+' cm')+'
' : '')+ '' : ''; return '
'+