feat: billed every 10 cm with 8 mm in the customer's favour, and the Site shows the whole sum (Marcus, 2026-11-27)
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 8m42s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m10s
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 8m42s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m10s
Marcus: a length that passes a 10 cm step by up to 8 mm is billed at that
step; by more, at the next. One rule for every product, on the server
(pricing.billed_length), the Site (arredonda10) and the Montador's estimate;
the print file accepts the 8 mm past the billed length instead of sending
the sheet to hand preparation.
The Site showed four numbers that did not add up (0,88 m, 4,42 m, 4,45 m,
4,50 m), and the team read 4,40 m. The copies line now gives the whole
sum ("5 × 88,4 cm + 4 espaços de 8 mm = 445,2 cm"), and the buy box says
why the billed metres are what they are, as a benefit ("os 4 mm a mais
ficam por nossa conta"). The buy box's parts note said 20 m; parts are
10 m since 18/11.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,19 @@ import os
|
|||||||
import re
|
import re
|
||||||
from decimal import Decimal, ROUND_CEILING
|
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}
|
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
|
# 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')
|
raise ValueError('Invalid product or length')
|
||||||
if isinstance(grade, bool) or not isinstance(grade, int) or not 0 <= grade <= 100:
|
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')
|
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:
|
if isinstance(extra_cents, bool) or not isinstance(extra_cents, int) or extra_cents < 0:
|
||||||
raise ValueError('Invalid extra charge')
|
raise ValueError('Invalid extra charge')
|
||||||
unit = (PRICES[mode] if unit_cents is None else unit_cents) + extra_cents
|
unit = (PRICES[mode] if unit_cents is None else unit_cents) + extra_cents
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ from decimal import Decimal
|
|||||||
from PIL import Image, ImageOps
|
from PIL import Image, ImageOps
|
||||||
|
|
||||||
from .core.models import PRODUCTION_VERSIONS
|
from .core.models import PRODUCTION_VERSIONS
|
||||||
|
from .core.pricing import STEP_GRACE_M
|
||||||
|
|
||||||
PT_PER_CM = 72 / 2.54
|
PT_PER_CM = 72 / 2.54
|
||||||
# Acrobat's page limit, 200 inches (5,08 m). A longer sheet is written at its
|
# 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']
|
production = item['production']
|
||||||
height = Decimal(str(production['height_cm']))
|
height = Decimal(str(production['height_cm']))
|
||||||
billed = Decimal(str(item['billed_metres'])) * 100
|
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')
|
raise Unsupported(f'a montagem tem {height} cm, mas só {billed} cm foram cobrados')
|
||||||
lowest = None
|
lowest = None
|
||||||
for placement in production['placements']:
|
for placement in production['placements']:
|
||||||
|
|||||||
@@ -165,8 +165,10 @@ class CartPricingCharacterizationTest(unittest.TestCase):
|
|||||||
split = priced('split-under-one-metre')
|
split = priced('split-under-one-metre')
|
||||||
self.assertEqual([(p['billed_metres'], p['total_cents']) for p in split],
|
self.assertEqual([(p['billed_metres'], p['total_cents']) for p in split],
|
||||||
[('0.8', 1752), ('0.2', 438)])
|
[('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]
|
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):
|
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
|
# Front 1a: 1 to 9 arts at R$ 9,90, from 10 at R$ 6,90, all arts charged
|
||||||
|
|||||||
@@ -16,9 +16,14 @@ class PricingTests(unittest.TestCase):
|
|||||||
source = Path('web/site-config.js').read_text()
|
source = Path('web/site-config.js').read_text()
|
||||||
prices = source.split('const PRECO=')[1].split(';',1)[0]
|
prices = source.split('const PRECO=')[1].split(';',1)[0]
|
||||||
calculator = source.split('const cobrar=')[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))
|
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];
|
const unit=PRECO[mode];
|
||||||
results.push([mode,String(metres),cobrar(metres),Math.round(unit*100),Math.round(cobrar(metres)*unit*100)]);
|
results.push([mode,String(metres),cobrar(metres),Math.round(unit*100),Math.round(cobrar(metres)*unit*100)]);
|
||||||
}process.stdout.write(JSON.stringify(results));'''
|
}process.stdout.write(JSON.stringify(results));'''
|
||||||
@@ -32,6 +37,18 @@ class PricingTests(unittest.TestCase):
|
|||||||
self.assertEqual(result['unit_cents'],unit)
|
self.assertEqual(result['unit_cents'],unit)
|
||||||
self.assertEqual(result['total_cents'],total)
|
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):
|
def test_one_price_per_product(self):
|
||||||
# Dropstar, 2026-10-23: textile R$ 19,90 ready sheet and R$ 21,90 loose
|
# 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).
|
# art; UV R$ 79,90 and R$ 89,90. Premium R$ 39,90 (2026-11-10).
|
||||||
|
|||||||
@@ -154,7 +154,8 @@ function montarQuoteFigures(lines){
|
|||||||
});
|
});
|
||||||
const catalog=MONTAR.catalog?.avulsa;
|
const catalog=MONTAR.catalog?.avulsa;
|
||||||
if(!catalog)throw new Error('Preço de tabela indisponível agora.');
|
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);
|
const total=+billed.reduce((sum,metres)=>sum+metres,0).toFixed(2);
|
||||||
let unit=catalog.unit_cents,best=null;
|
let unit=catalog.unit_cents,best=null;
|
||||||
for(const band of catalog.bands||[]){
|
for(const band of catalog.bands||[]){
|
||||||
|
|||||||
@@ -12,13 +12,24 @@
|
|||||||
$('cMetroLbl').textContent = it.extra ? 'Metro · com '+rs(it.extra)+' de arquivo manual' : 'Metro';
|
$('cMetroLbl').textContent = it.extra ? 'Metro · com '+rs(it.extra)+' de arquivo manual' : 'Metro';
|
||||||
$('cMetro').textContent=rs(it.unit);
|
$('cMetro').textContent=rs(it.unit);
|
||||||
$('cMetragem').textContent=fmtM(it.cob)+' m';
|
$('cMetragem').textContent=fmtM(it.cob)+' m';
|
||||||
const partes=ehFolha(it.modo) ? Math.ceil(it.metros/20) : 1;
|
// Partes de até 10 m (Marcus, 18/11/2026): o FlexiPRINT não abre mais que isso.
|
||||||
$('cPartes').textContent = partes>1 ? ' Sai em '+partes+' partes de até 20 m.' : '';
|
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);
|
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 =
|
$('cObs').textContent =
|
||||||
it.cob===MINIMO_M && it.metros<MINIMO_M
|
it.cob===MINIMO_M && it.metros<MINIMO_M
|
||||||
? (ehFolha(it.modo) ? 'Pedido mínimo de 1 m.'
|
? (ehFolha(it.modo) ? 'Pedido mínimo de 1 m.'
|
||||||
: 'Pedido mínimo de 1 m: ainda cabem '+sobraCm+' cm de artes sem custo.')
|
: 'Pedido mínimo de 1 m: ainda cabem '+sobraCm+' cm de artes sem custo.')
|
||||||
|
: it.cob<it.metros-1e-6
|
||||||
|
? 'A folha tem '+exata+': cobramos a cada 10 cm e '+
|
||||||
|
(aMais>1?'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);
|
$('cTotal').textContent=rs(it.total);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
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;
|
const larguraFilme=()=>MODOS[modo].larg;
|
||||||
// cobrança proporcional: arredonda para cima em 10 cm · 2,75 m vira 2,80 m
|
// Cobrança a cada 10 cm, com 8 mm a favor do cliente (Marcus, 27/11/2026):
|
||||||
const cobrar=m=>Math.max(MINIMO_M, Math.ceil(m*10)/10);
|
// 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
|
// 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.
|
// 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 cobrarMontagem=()=>!ehFolha() && montagemFolhas ? cobrarFolhas(montagemFolhas) : cobrar(metros);
|
||||||
const fmtM=m=>m.toFixed(2).replace('.',',');
|
const fmtM=m=>m.toFixed(2).replace('.',',');
|
||||||
const cls=n=>n>=85?'ok':n>=50?'av':'er';
|
const cls=n=>n>=85?'ok':n>=50?'av':'er';
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ function montaFolhasDeTraco(grupos,W){
|
|||||||
figura.append(legenda,desenho); painel.append(figura);
|
figura.append(legenda,desenho); painel.append(figura);
|
||||||
desenhaMontagem(desenho, lista, 0, W, uso, r=>{
|
desenhaMontagem(desenho, lista, 0, W, uso, r=>{
|
||||||
if(area.montagemVersao!==versao) return; // a montagem mudou nesse meio-tempo
|
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,
|
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};
|
layout:r.placements ? {height_cm:+r.alturaCm.toFixed(4), placements:r.placements} : null};
|
||||||
if(feitas.filter(Boolean).length<grupos.length) return;
|
if(feitas.filter(Boolean).length<grupos.length) return;
|
||||||
|
|||||||
@@ -620,7 +620,12 @@ function pintaFolha(){
|
|||||||
'<span class="passo"><button type="button" data-passo="-1" data-i="'+i+'" aria-label="Menos uma cópia">−</button>'+
|
'<span class="passo"><button type="button" data-passo="-1" data-i="'+i+'" aria-label="Menos uma cópia">−</button>'+
|
||||||
'<input type="number" id="repf'+i+'" min="1" max="200" data-repf="'+i+'" value="'+x.rep+'">'+
|
'<input type="number" id="repf'+i+'" min="1" max="200" data-repf="'+i+'" value="'+x.rep+'">'+
|
||||||
'<button type="button" data-passo="1" data-i="'+i+'" aria-label="Mais uma cópia">+</button></span></div>'+
|
'<button type="button" data-passo="1" data-i="'+i+'" aria-label="Mais uma cópia">+</button></span></div>'+
|
||||||
'<div class="conta">'+(x.rep>1? x.rep+' × '+fmtM(x.m)+' m = ' : '')+'<b>'+fmtM(sub)+' m</b></div>' : '')+
|
// 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").
|
||||||
|
'<div class="conta">'+(x.rep>1
|
||||||
|
? x.rep+' × '+n1(x.m*100)+' cm + '+(x.rep-1)+(x.rep>2?' espaços':' espaço')+' de 8 mm = <b>'+
|
||||||
|
n1(sub*100+(x.rep-1)*MARGEM_FOLHA_CM)+' cm</b>'
|
||||||
|
: '<b>'+n1(x.m*100)+' cm</b>')+'</div>' : '')+
|
||||||
'</div>' : '';
|
'</div>' : '';
|
||||||
return '<div class="rep" data-folha="'+i+'">'+
|
return '<div class="rep" data-folha="'+i+'">'+
|
||||||
'<div class="repTopo"><div class="miniF">'+mini+'</div><div class="repInfo">'+
|
'<div class="repTopo"><div class="miniF">'+mini+'</div><div class="repInfo">'+
|
||||||
|
|||||||
Reference in New Issue
Block a user