feat: one price per product; the grade is shown but no longer prices
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 3m58s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m11s

Dropstar asked on 2026-10-23 to drop the five-band ladder by grade:
textile R$ 19,90 a ready sheet and R$ 21,90 loose art, UV R$ 79,90 and
R$ 89,90.

- the server charges PRICES (app/core/pricing.py) whatever the grade; the
  grade is still validated and kept with the item, and discount_cents is gone
- a file opened by hand pays the product's price plus MANUAL_FILE_EXTRA_CENTS
- the Site's PRECO replaces FAIXAS, TABELA and MONTAGEM; the top chip, the
  home example, the product cards, the selector and the price table read it
  (data-preco), so no page still says "a partir de R$ 14,90"
- no "Desconto pela nota", ladder, "cai até" or "sai mais barato" anywhere;
  the buy box shows "Nota da arte" on its own line, the 96 DPI refusal and the
  resolution warning stay
- the review reason "Nota informada sem análise da arte" is removed: it only
  stopped a discount. The server still checks the grade against the files,
  so the grade shown on the Kanban and in Tiny stays honest
- the Tiny probe's test order uses the single price
- docs/CONTEXT.md: Commercial rules and Still to do

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-26 11:07:00 -03:00
parent 629628a522
commit 88819c3a5f
23 changed files with 211 additions and 210 deletions

View File

@@ -3,39 +3,51 @@ import json
from pathlib import Path
import subprocess
import unittest
from app.core.pricing import is_manual, price, TIERS
from app.core.pricing import is_manual, price, PRICES
class PricingTests(unittest.TestCase):
def test_every_grade_against_actual_site_javascript(self):
# The ladders live with the rest of the Site's behaviour; this test exists
def test_every_length_against_actual_site_javascript(self):
# The prices live with the rest of the Site's behaviour; this test exists
# to prove the server agrees with whatever the customer is shown.
source = Path('web/site-config.js').read_text()
tiers = source.split('const FAIXAS=')[1].split('\n};',1)[0]+'\n}'
prices = source.split('const PRECO=')[1].split(';',1)[0]
calculator = source.split('const cobrar=')[1].split(';',1)[0]
js = f'const FAIXAS={tiers};const MINIMO_M=1;const cobrar={calculator};'
js += '''const results=[];for(const mode of Object.keys(FAIXAS))for(let grade=0;grade<=100;grade++)
js = f'const PRECO={prices};const MINIMO_M=1;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]){
const unit=FAIXAS[mode].find(x=>grade>=x[0])[1];
results.push([mode,String(metres),grade,cobrar(metres),Math.round(unit*100),Math.round(cobrar(metres)*unit*100)]);
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));'''
cases = json.loads(subprocess.check_output(['node','-e',js],text=True))
for mode,metres,grade,billed,unit,total in cases:
with self.subTest(mode=mode,metres=metres,grade=grade):
result=price(mode,metres,grade)
self.assertEqual(float(result['billed_metres']),billed)
self.assertEqual(result['unit_cents'],unit)
self.assertEqual(result['total_cents'],total)
self.assertEqual({mode for mode, *_ in cases}, set(PRICES))
for mode,metres,billed,unit,total in cases:
for grade in (0, 39, 40, 75, 90, 100):
with self.subTest(mode=mode,metres=metres,grade=grade):
result=price(mode,metres,grade)
self.assertEqual(float(result['billed_metres']),billed)
self.assertEqual(result['unit_cents'],unit)
self.assertEqual(result['total_cents'],total)
def test_assembly_is_included_at_every_tier(self):
for grade in range(101):
self.assertEqual(price('avulsa','1',grade)['total_cents']-price('file','1',grade)['total_cents'],1000)
self.assertEqual(price('uv','1',grade)['total_cents']-price('uvfile','1',grade)['total_cents'],1400)
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.
self.assertEqual(PRICES, {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990})
self.assertEqual(price('avulsa', '2.75', 90)['total_cents'], 6132)
def test_manual_file_extra_is_per_metre_and_not_a_discount(self):
def test_the_grade_never_changes_the_price(self):
for mode in PRICES:
charges = {(p['unit_cents'], p['total_cents']) for p in (price(mode, '2.75', g) for g in range(101))}
self.assertEqual(len(charges), 1, mode)
self.assertNotIn('discount_cents', price(mode, '1', 100))
# The grade is still kept with the item, for the Kanban and Tiny.
self.assertEqual(price('file', '1', 92)['grade'], 92)
def test_manual_file_extra_is_per_metre(self):
plain, extra = price('file', '1.01', 0), price('file', '1.01', 0, 500)
self.assertEqual(extra['unit_cents'], plain['unit_cents'] + 500)
self.assertEqual(extra['total_cents'], plain['total_cents'] + 550)
self.assertEqual(extra['discount_cents'], 0)
# On top of the single price, whatever grade the item carries.
self.assertEqual(price('file', '1', 100, 200)['unit_cents'], 2190)
self.assertEqual(extra['manual_extra_cents'], 500)
self.assertNotIn('manual_extra_cents', plain)
for bad in (-1, True, 1.5):