feat: Ajuste Fino priced per art, with the offer under each Prumo warning (Marcus 10/11, point 1)
The designer treatment becomes Ajuste Fino, priced per art with a batch band set in the Site tab (e.g. R$ 9,90, from 10 arts R$ 6,90). Under each art the Prumo warns about, the Site offers 'Quer que um designer resolva? Ajuste Fino'; the cart keeps 'Ajuste Fino em todas as artes'. The server counts the chosen arts, Tiny gets the line with that quantity, the card shows 'Ajuste Fino · N artes'. Old carts asking the treatment for the whole order keep working. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,12 +4,15 @@ Run against the local stack: SITE_BASE_URL=http://site SITE_HOST_HEADER=localhos
|
||||
python -m tests.site_admin_test
|
||||
"""
|
||||
import io
|
||||
import os
|
||||
import secrets
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
from unittest import mock
|
||||
from uuid import uuid4
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from app import tiny
|
||||
from app.core import db
|
||||
from tests.print_file_test import artwork
|
||||
from tests.smoke_test import Client, item_spec, upload_bytes
|
||||
@@ -34,6 +37,20 @@ def quote(client, item, mail, expected=200):
|
||||
'items': [item], 'freight': {'service': 'pickup'}}, expected=expected)
|
||||
|
||||
|
||||
def arts_item(upload_id, arts):
|
||||
"""One loose-art item with `arts` sources of 10 x 10 cm, one metre long."""
|
||||
sources = [{'upload_id': upload_id, 'kind': 'artwork', 'width_cm': 10, 'length_cm': 10,
|
||||
'copies': 1, 'rotation_degrees': 0, 'mirrored': False,
|
||||
'measurement': 'customer'} for _ in range(arts)]
|
||||
placements = [{'source_index': index, 'copy_index': 0, 'x_cm': 0, 'y_cm': index * 10,
|
||||
'width_cm': 10, 'length_cm': 10, 'rotation_degrees': 0, 'mirrored': False}
|
||||
for index in range(arts)]
|
||||
return {'mode': 'avulsa', 'metres': '1', 'grade': 90, 'uploads': [upload_id] * arts,
|
||||
'production': {'version': 3, 'film_width_cm': 57, 'height_cm': arts * 10,
|
||||
'sources': sources, 'placements': placements},
|
||||
'quality_status': 'ok', 'quality_acknowledged': False}
|
||||
|
||||
|
||||
def run():
|
||||
tag = secrets.token_hex(4)
|
||||
mail = f'site-admin-{tag}@example.test'
|
||||
@@ -44,12 +61,12 @@ def run():
|
||||
manager.call('/session')
|
||||
manager.call('/operator/me', operator=True)
|
||||
manager = manager.operator_client
|
||||
prices, user = [], None
|
||||
prices, user, treatment_enabled = [], None, None
|
||||
try:
|
||||
products = manager.call('/operator/site/products')['products']
|
||||
assert {product['id'] for product in products} == \
|
||||
{'file', 'avulsa', 'uvfile', 'uv', 'premium', 'tratamento'}
|
||||
assert all(product['unit'] in ('metro', 'pedido') and product['title'] for product in products)
|
||||
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).
|
||||
premium_entry = next(product for product in products if product['id'] == PREMIUM)
|
||||
@@ -71,6 +88,46 @@ def run():
|
||||
assert approved['total_cents'] == 3990, approved
|
||||
manager.call(f'/operator/site/products/{PREMIUM}', {'enabled': False})
|
||||
|
||||
# Front 1a: Ajuste Fino per art, with the batch band set in the Site tab.
|
||||
treatment = next(product for product in products if product['id'] == 'tratamento')
|
||||
treatment_enabled = treatment['enabled']
|
||||
manager.call('/operator/site/products/tratamento', {'enabled': True})
|
||||
made = manager.call('/operator/site/products/tratamento/prices', {
|
||||
'unit_cents': 990, 'bands': [{'from_metres': '10', 'unit_cents': 690}]})
|
||||
prices.append(made['id'])
|
||||
session = client.call('/session')
|
||||
assert session['treatment_cents'] == 990, session
|
||||
assert session['treatment_bands'] == [{'from_metres': 10.0, 'unit_cents': 690}], session
|
||||
arts = arts_item(upload_bytes(client, artwork(), name='LOCAL-AJUSTE-FINO.png'), 10)
|
||||
customer = {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': mail}
|
||||
three = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
|
||||
'items': [arts], 'treatment': [[0, 0], [0, 1], [0, 2]],
|
||||
'freight': {'service': 'pickup'}})
|
||||
assert three['status'] == 'approved', three
|
||||
ajuste = client.call('/quotes/' + three['id'])['approved']
|
||||
assert ajuste['treatment'] == {'cents': 2970, 'hours': 24, 'arts': 3,
|
||||
'unit_cents': 990}, ajuste
|
||||
assert ajuste['total_cents'] == ajuste['items'][0]['total_cents'] + 2970, ajuste
|
||||
ten = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
|
||||
'items': [arts], 'treatment': [[0, index] for index in range(10)],
|
||||
'freight': {'service': 'pickup'}})
|
||||
ten = client.call('/quotes/' + ten['id'])['approved']
|
||||
assert ten['treatment'] == {'cents': 6900, 'hours': 24, 'arts': 10,
|
||||
'unit_cents': 690}, ten
|
||||
old = client.call('/quotes', {'request_key': str(uuid4()), 'customer': customer,
|
||||
'items': [arts], 'treatment': True, 'freight': {'service': 'pickup'}})
|
||||
old = client.call('/quotes/' + old['id'])['approved']
|
||||
assert old['treatment'] == {'cents': 6900, 'hours': 24, 'arts': 10,
|
||||
'unit_cents': 690}, old
|
||||
# Tiny: the quantity is the number of arts and the unit is the band price.
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '105'}):
|
||||
pedido = tiny.order_payload({'order_id': three['id'], 'order': ajuste,
|
||||
'number': 1, 'payment': {}, 'origin': 'site'}, 777,
|
||||
date(2026, 11, 11), product_id=lambda code: 999)
|
||||
assert [line for line in pedido['itens'] if line['produto']['id'] == 105] == [
|
||||
{'produto': {'id': 105}, 'quantidade': 3, 'valorUnitario': 9.9,
|
||||
'infoAdicional': 'Ajuste Fino · 3 artes · +24 h'}], pedido['itens']
|
||||
|
||||
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}
|
||||
@@ -143,8 +200,6 @@ def run():
|
||||
manager.call(f'/operator/site/products/{UV}/prices', {
|
||||
'unit_cents': 12345, 'bands': [{'from_metres': str(i), 'unit_cents': 1900}
|
||||
for i in range(1, 7)]}, expected=422)
|
||||
manager.call('/operator/site/products/tratamento/prices', {
|
||||
'unit_cents': 1000, 'bands': [{'from_metres': '5', 'unit_cents': 900}]}, expected=422)
|
||||
|
||||
# A profile without "manage" cannot see or change the Site tab.
|
||||
email = f'site-staff-{tag}@example.test'
|
||||
@@ -158,14 +213,19 @@ def run():
|
||||
staff.call(f'/operator/site/products/{UV}/prices', {'unit_cents': 1000}, expected=403)
|
||||
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, schedules and cancels prices, charges the new price,'
|
||||
' and refuses a non-manage profile')
|
||||
' and accepts it once enabled, prices Ajuste Fino per art with its band,'
|
||||
' schedules and cancels prices, charges the new price, and refuses a non-manage profile')
|
||||
finally:
|
||||
with db.connect() as c:
|
||||
if prices:
|
||||
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 treatment_enabled is not None:
|
||||
try:
|
||||
manager.call('/operator/site/products/tratamento', {'enabled': treatment_enabled})
|
||||
except Exception:
|
||||
pass
|
||||
if user:
|
||||
try:
|
||||
manager.call('/operator/users/' + str(user['id']) + '/delete', {}, expected=200)
|
||||
|
||||
Reference in New Issue
Block a user