feat: Ajuste Fino Redesenho in the cart (Marcus 12/11, slice R1)

Under each art the Prumo warns about, the customer can choose Ajuste Fino
or Ajuste Fino Redesenho (vectorize or redraw, per art, +48 h, no batch
price). It is a disabled product until Gestão prices it in the Site tab;
the server charges it per chosen art, Tiny gets a DTFIMP.AJF.RED line and
two more business days, the card shows 'Redesenho · N artes' and the
designer gate applies. The preview loop is slice R2.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-12 11:05:17 -03:00
parent 5ca6792221
commit 38f947d632
23 changed files with 429 additions and 60 deletions

View File

@@ -13,6 +13,7 @@ from uuid import uuid4
from PIL import Image, ImageDraw
from app import tiny
from app.adapters import FakeTiny
from app.core import db
from tests.print_file_test import artwork
from tests.smoke_test import Client, item_spec, upload_bytes
@@ -20,6 +21,7 @@ from tests.smoke_test import Client, item_spec, upload_bytes
PASSWORD = 'senha-de-teste-123'
UV = 'uv'
PREMIUM = 'premium'
REDESIGN = 'redesenho'
def premium_sheet():
@@ -61,11 +63,11 @@ def run():
manager.call('/session')
manager.call('/operator/me', operator=True)
manager = manager.operator_client
prices, user, treatment_enabled = [], None, None
prices, user, treatment_enabled, redesign_enabled = [], None, None, None
try:
products = manager.call('/operator/site/products')['products']
assert {product['id'] for product in products} == \
{'file', 'avulsa', 'uvfile', 'uv', 'premium', 'tratamento'}
{'file', 'avulsa', 'uvfile', 'uv', 'premium', 'tratamento', REDESIGN}
assert all(product['unit'] in ('metro', 'pedido', 'arte') and product['title'] for product in products)
# Front 3: Premium is listed and starts switched off (Marcus, 2026-11-10).
@@ -128,6 +130,62 @@ def run():
{'produto': {'id': 105}, 'quantidade': 3, 'valorUnitario': 9.9,
'infoAdicional': 'Ajuste Fino · 3 artes · +24 h'}], pedido['itens']
# Front 1b: Ajuste Fino Redesenho, one price per art, never a band.
redesign = next(product for product in products if product['id'] == REDESIGN)
redesign_enabled = redesign['enabled']
assert redesign['enabled'] is False, redesign
assert redesign['title'] == 'Ajuste Fino Redesenho', redesign
assert redesign['unit'] == 'arte', redesign
manager.call(f'/operator/site/products/{REDESIGN}', {'enabled': True})
# Enabled but still unpriced: the Site hides it and the server refuses it.
refused = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
'items': [arts], 'redesign': [[0, 0]], 'freight': {'service': 'pickup'}}, expected=422)
assert refused['detail'] == 'O Redesenho não está disponível agora.', refused
banded = manager.call(f'/operator/site/products/{REDESIGN}/prices', {
'unit_cents': 2990,
'bands': [{'from_metres': '10', 'unit_cents': 690}]}, expected=422)
assert 'faixas' in banded['detail'], banded
made = manager.call(f'/operator/site/products/{REDESIGN}/prices', {'unit_cents': 2990})
prices.append(made['id'])
assert client.call('/session')['redesign_cents'] == 2990
two = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
'items': [arts], 'redesign': [[0, 0], [0, 1]], 'freight': {'service': 'pickup'}})
assert two['status'] == 'approved', two
redesenho = client.call('/quotes/' + two['id'])['approved']
assert redesenho['redesign'] == {'cents': 5980, 'hours': 48, 'arts': 2,
'unit_cents': 2990}, redesenho
assert redesenho['total_cents'] == redesenho['items'][0]['total_cents'] + 5980, redesenho
# Basic and Redesenho on different arts: each priced on its own service,
# and the basic band counts only the basic arts.
mixed = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
'items': [arts], 'treatment': [[0, 0], [0, 1], [0, 2]],
'redesign': [[0, 3], [0, 4]], 'freight': {'service': 'pickup'}})
mixed = client.call('/quotes/' + mixed['id'])['approved']
assert mixed['treatment'] == {'cents': 2970, 'hours': 24, 'arts': 3,
'unit_cents': 990}, mixed
assert mixed['redesign'] == {'cents': 5980, 'hours': 48, 'arts': 2,
'unit_cents': 2990}, mixed
assert mixed['total_cents'] == mixed['items'][0]['total_cents'] + 2970 + 5980, mixed
# Tiny: the line resolves DTFIMP.AJF.RED through the fake catalogue.
fake = FakeTiny()
pedido = tiny.order_payload({'order_id': two['id'], 'order': redesenho,
'number': 2, 'payment': {}, 'origin': 'site'}, 777,
date(2026, 11, 12), product_id=fake.product_id)
red_code = fake.product_id('DTFIMP.AJF.RED')
assert [line for line in pedido['itens'] if line['produto']['id'] == red_code] == [
{'produto': {'id': red_code}, 'quantidade': 2, 'valorUnitario': 29.9,
'infoAdicional': 'Ajuste Fino Redesenho · 2 artes · +48 h'}], pedido['itens']
# One service per art: a pair in both lists is refused by the model.
both = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
'items': [arts], 'treatment': [[0, 0]], 'redesign': [[0, 0]],
'freight': {'service': 'pickup'}}, expected=422)
assert 'Escolha Ajuste Fino ou Redesenho' in str(both['detail']), both
# Switched off again, a chosen Redesenho is refused.
manager.call(f'/operator/site/products/{REDESIGN}', {'enabled': False})
refused = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
'items': [arts], 'redesign': [[0, 0]], 'freight': {'service': 'pickup'}}, expected=422)
assert refused['detail'] == 'O Redesenho não está disponível agora.', refused
manager.call(f'/operator/site/products/{UV}', {'enabled': True})
uid = upload_bytes(client, artwork(), name='LOCAL-SITE-ADMIN.png')
item = {**item_spec('uv', '1', 0, uid), 'quality_status': 'warning', 'quality_acknowledged': True}
@@ -214,6 +272,7 @@ def run():
staff.call(f'/operator/site/prices/{made["id"]}/cancel', {}, expected=403)
print('PASS: the Site tab switches a product off and refuses quotes, lists Premium switched off'
' and accepts it once enabled, prices Ajuste Fino per art with its band,'
' prices Redesenho per art without bands and sends it to Tiny,'
' schedules and cancels prices, charges the new price, and refuses a non-manage profile')
finally:
with db.connect() as c:
@@ -221,6 +280,9 @@ def run():
c.execute('DELETE FROM dtf_local.product_prices WHERE id=ANY(%s::bigint[])', (prices,))
c.execute("UPDATE dtf_local.products SET enabled=true WHERE id=%s", (UV,))
c.execute("UPDATE dtf_local.products SET enabled=false WHERE id=%s", (PREMIUM,))
if redesign_enabled is not None:
c.execute("UPDATE dtf_local.products SET enabled=%s WHERE id=%s",
(redesign_enabled, REDESIGN))
if treatment_enabled is not None:
try:
manager.call('/operator/site/products/tratamento', {'enabled': treatment_enabled})

View File

@@ -8,10 +8,21 @@ extra. app/cart_pricing.price_items must return exactly the same list.
import unittest
from decimal import Decimal
from uuid import uuid4
from app import catalog
from app.cart_pricing import price_items, treatment_price
from app.cart_pricing import (designer_hours, needs_designer, price_items,
redesign_price, treatment_price)
from app.core import pricing
try:
from pydantic import ValidationError
from app.core.models import QuoteRequest
except ImportError:
# The validate job runs this file on the host, without the runtime image's
# dependencies; the runtime suites exercise the model there.
QuoteRequest = ValidationError = None
BASE = {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990}
UV_BANDS = [{'from_metres': '5', 'unit_cents': 8000},
@@ -24,6 +35,7 @@ def catalog_now(bands=None, prices=None):
now = {mode: {'enabled': True, 'unit_cents': prices[mode],
'bands': bands.get(mode, [])} for mode in BASE}
now['tratamento'] = {'enabled': True, 'unit_cents': 1000, 'bands': []}
now['redesenho'] = {'enabled': True, 'unit_cents': 2990, 'bands': []}
return now
@@ -171,6 +183,67 @@ class CartPricingCharacterizationTest(unittest.TestCase):
self.assertEqual(treatment_price(items, [], offer), {})
self.assertEqual(treatment_price(items, True, {**offer, 'enabled': False}), {})
def test_redesenho_is_per_art_never_a_band(self):
# Front 1b: R$ 29,90 per art, and the basic batch band never applies.
offer = {'enabled': True, 'unit_cents': 2990,
'bands': [{'from_metres': '10', 'unit_cents': 690}]}
items = [item('file', '1', uid='u1'), item('file', '1', uid='u2')]
self.assertEqual(redesign_price(items, [[0, 0], [1, 0]], offer),
{'cents': 5980, 'hours': 48, 'arts': 2, 'unit_cents': 2990})
self.assertEqual(redesign_price(items, [], offer), {})
self.assertEqual(redesign_price(items, [[0, 0]], {**offer, 'enabled': False}), {})
self.assertEqual(redesign_price(items, [[0, 0]], {**offer, 'unit_cents': 0}), {})
def test_the_basic_band_counts_only_basic_arts(self):
offer = {'enabled': True, 'unit_cents': 990,
'bands': [{'from_metres': '10', 'unit_cents': 690}]}
items = [item('avulsa', '1', uid=f'u{index}') for index in range(10)]
basic = [[index, 0] for index in range(9)]
self.assertEqual(treatment_price(items, basic, offer),
{'cents': 8910, 'hours': 24, 'arts': 9, 'unit_cents': 990})
redesign = redesign_price(items, [[9, 0]], offer={**offer, 'unit_cents': 2990})
self.assertEqual(redesign['arts'], 1)
def test_designer_helpers_read_both_services(self):
self.assertEqual(designer_hours({}), 0)
self.assertEqual(designer_hours({'treatment': {'cents': 990}}), 24)
self.assertEqual(designer_hours({'redesign': {'cents': 2990}}), 48)
self.assertEqual(designer_hours({'treatment': {'cents': 990},
'redesign': {'cents': 2990}}), 48)
self.assertFalse(needs_designer({}))
self.assertTrue(needs_designer({'treatment': {'cents': 990}}))
self.assertTrue(needs_designer({'redesign': {'cents': 2990}}))
@unittest.skipUnless(QuoteRequest, 'pydantic is only in the runtime image')
def test_a_pair_cannot_be_basic_and_redesenho(self):
def quote(treatment=None, redesign=None, items=1):
entries = []
for _ in range(items):
uid = str(uuid4())
data = item('avulsa', '1', uid=uid)
data['production']['placements'] = [{
'source_index': 0, 'copy_index': 0, 'x_cm': 0, 'y_cm': 0,
'width_cm': 10, 'length_cm': 10, 'rotation_degrees': 0, 'mirrored': False}]
entries.append(data)
payload = {'request_key': str(uuid4()),
'customer': {'cnpj': '11222333000181', 'zap': '11999999999',
'mail': 'arte@example.test'},
'items': entries, 'freight': {'service': 'pickup'}}
if treatment is not None:
payload['treatment'] = treatment
if redesign is not None:
payload['redesign'] = redesign
return payload
QuoteRequest.model_validate(quote(treatment=[[0, 0]], redesign=[[1, 0]], items=2))
with self.assertRaises(ValidationError):
QuoteRequest.model_validate(quote(treatment=[[0, 0]], redesign=[[0, 0]]))
with self.assertRaises(ValidationError):
QuoteRequest.model_validate(quote(treatment=True, redesign=[[0, 0]]))
with self.assertRaises(ValidationError):
QuoteRequest.model_validate(quote(redesign=[[0, 0], [0, 0]]))
with self.assertRaises(ValidationError):
QuoteRequest.model_validate(quote(redesign=[[1, 0]]))
if __name__ == '__main__':
unittest.main()