Merge main into montador-v2
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> # Conflicts: # web/kanban.js
This commit is contained in:
@@ -26,6 +26,7 @@ jobs:
|
||||
tests.test_db_pool \
|
||||
tests.test_coupons \
|
||||
tests.test_grade_rules \
|
||||
tests.test_hotfolder \
|
||||
tests.test_migrate \
|
||||
tests.test_secrets -v
|
||||
sh -n infra/lock_dependencies.sh
|
||||
|
||||
@@ -53,6 +53,8 @@ def sheet(mid: UUID, user=Depends(can('view'))):
|
||||
'counters': machine_log.counters(c, mid),
|
||||
'supplies': machine_log.supply_estimates(c, mid),
|
||||
'minimums': minimums,
|
||||
# The values the sheet shows when Gestão has not typed one.
|
||||
'default_minimums': machine_log.DEFAULT_MINIMUMS,
|
||||
'alerts': machine_log.alerts(c, mid),
|
||||
'entries': [{**row, 'label': entry_label(row)} for row in entries],
|
||||
'catalog': {'supplies': machine_log.SUPPLIES, 'parts': machine_log.PARTS,
|
||||
|
||||
@@ -65,8 +65,8 @@ def cursor_pair(first, second):
|
||||
return first is not None
|
||||
|
||||
|
||||
MODES = {'textil': {'file', 'avulsa'}, 'uv': {'uvfile', 'uv'},
|
||||
'folha': {'file', 'uvfile'}, 'avulsa': {'avulsa', 'uv'}}
|
||||
MODES = {'textil': {'file', 'avulsa', 'premium'}, 'uv': {'uvfile', 'uv'},
|
||||
'folha': {'file', 'uvfile', 'premium'}, 'avulsa': {'avulsa', 'uv'}}
|
||||
|
||||
|
||||
def like(text):
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
Dropstar, 2026-11-05 (Fase 2, front 8): the products and their prices leave the
|
||||
code and live in the database, with a start date and a history. `PRICES` in
|
||||
app/core/pricing.py stays as the seed and the fallback for the four modes;
|
||||
app/core/pricing.py stays as the seed and the fallback for the five modes;
|
||||
`treatment_cents()` stays as the fallback for `tratamento`. A price row is never
|
||||
changed or deleted once its start date has passed (the table is the history),
|
||||
and an approved quote keeps the price it was approved with.
|
||||
@@ -19,8 +19,8 @@ from decimal import Decimal
|
||||
|
||||
from .core import pricing
|
||||
|
||||
# The four modes sold by the metre, and the treatment sold per order.
|
||||
MODES = ('file', 'avulsa', 'uvfile', 'uv')
|
||||
# The modes sold by the metre, and the treatment sold per order.
|
||||
MODES = ('file', 'avulsa', 'uvfile', 'uv', 'premium')
|
||||
PRODUCTS = (*MODES, 'tratamento')
|
||||
|
||||
TITLES = {
|
||||
@@ -28,10 +28,11 @@ TITLES = {
|
||||
'avulsa': 'Têxtil artes avulsas',
|
||||
'uvfile': 'UV folha pronta',
|
||||
'uv': 'UV artes avulsas',
|
||||
'premium': 'Têxtil Premium · 8 passadas',
|
||||
'tratamento': 'Tratamento pelo designer',
|
||||
}
|
||||
UNITS = {'file': 'metro', 'avulsa': 'metro', 'uvfile': 'metro', 'uv': 'metro',
|
||||
'tratamento': 'pedido'}
|
||||
'premium': 'metro', 'tratamento': 'pedido'}
|
||||
|
||||
|
||||
def fallback_cents(product: str) -> int:
|
||||
|
||||
@@ -174,7 +174,7 @@ def check_splits(items):
|
||||
|
||||
|
||||
class Item(StrictModel):
|
||||
mode: Literal['file','avulsa','uvfile','uv']
|
||||
mode: Literal['file','avulsa','uvfile','uv','premium']
|
||||
metres: Decimal = Field(gt=0, le=12000)
|
||||
grade: int = Field(ge=0, le=100, strict=True)
|
||||
uploads: list[UUID] = Field(min_length=1, max_length=20)
|
||||
@@ -205,7 +205,7 @@ class Item(StrictModel):
|
||||
raise ValueError('Only loose artwork is split into sheets')
|
||||
if [source.upload_id for source in self.production.sources] != self.uploads:
|
||||
raise ValueError('Production sources must match uploaded files in order')
|
||||
is_sheet = self.mode in ('file', 'uvfile')
|
||||
is_sheet = self.mode in ('file', 'uvfile', 'premium')
|
||||
# UV is 27 cm wide (Dropstar, 2026-10-28; it was 28,5).
|
||||
film_width = Decimal('27') if self.mode in ('uvfile', 'uv') else Decimal('57')
|
||||
if self.production.film_width_cm != film_width:
|
||||
@@ -406,7 +406,7 @@ class CouponNew(StrictModel):
|
||||
min_metres: Decimal | None = Field(default=None, gt=0, decimal_places=1)
|
||||
max_uses: int | None = Field(default=None, gt=0, strict=True)
|
||||
max_uses_per_customer: int | None = Field(default=None, gt=0, strict=True)
|
||||
product: Literal['file', 'avulsa', 'uvfile', 'uv'] | None = None
|
||||
product: Literal['file', 'avulsa', 'uvfile', 'uv', 'premium'] | None = None
|
||||
note: str = Field(default='', max_length=1000)
|
||||
|
||||
|
||||
@@ -419,7 +419,7 @@ class CouponUpdate(StrictModel):
|
||||
min_metres: Decimal | None = Field(default=None, gt=0, decimal_places=1)
|
||||
max_uses: int | None = Field(default=None, gt=0, strict=True)
|
||||
max_uses_per_customer: int | None = Field(default=None, gt=0, strict=True)
|
||||
product: Literal['file', 'avulsa', 'uvfile', 'uv'] | None = None
|
||||
product: Literal['file', 'avulsa', 'uvfile', 'uv', 'premium'] | None = None
|
||||
note: str | None = Field(default=None, max_length=1000)
|
||||
paused: bool | None = None
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import os
|
||||
import re
|
||||
from decimal import Decimal, ROUND_CEILING
|
||||
|
||||
PRICES = {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990}
|
||||
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
|
||||
# person before printing. It pays this per metre on top of the product's price
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Each machine's hot folders (Dropstar's third round, item 10, 2026-10-29/30).
|
||||
|
||||
FlexiPRINT watches 3. Imprimindo/<máquina>/<C1|C2|C3>/ and takes a file out
|
||||
of it when it rips. When the operator pulls a card to Imprimindo, its files
|
||||
go, as a copy, into its machine's folder for the item's contraction class;
|
||||
FlexiPRINT watches 3. Imprimindo/<máquina>/<C1|C2|C3|PREMIUM>/ and takes a
|
||||
file out of it when it rips. When the operator pulls a card to Imprimindo, its
|
||||
files go, as a copy, into its machine's folder for the item's contraction
|
||||
class; a premium item always goes to PREMIUM, whichever class it carries;
|
||||
the order's own file stays in its stage folder. A film over 15 m is several
|
||||
parts (item 13): all on the same machine, in order, never more than two in
|
||||
the folder at once. The third is written when Flexi takes the first.
|
||||
@@ -27,6 +28,8 @@ IN_FOLDER = 2
|
||||
# A computer that claimed a part and never said it was written.
|
||||
CLAIM_TIMEOUT = timedelta(minutes=10)
|
||||
CLASSES = ('C1', 'C2', 'C3')
|
||||
# The premium product's own folder (Dropstar, 2026-11-10, front 3).
|
||||
PREMIUM = 'PREMIUM'
|
||||
|
||||
|
||||
def contraction(order, index):
|
||||
@@ -41,6 +44,13 @@ def contraction(order, index):
|
||||
return item.get('stroke_class') if item.get('stroke_class') in CLASSES else None
|
||||
|
||||
|
||||
def folder_class(order, index):
|
||||
"""The folder an item's parts go to: PREMIUM for the premium product,
|
||||
whatever contraction class is recorded, else C1/C2/C3."""
|
||||
item = order['snapshot']['items'][index]
|
||||
return PREMIUM if item.get('mode') == 'premium' else contraction(order, index)
|
||||
|
||||
|
||||
def start(c, order_id):
|
||||
"""The order entered Imprimindo: its approved finals queue for its
|
||||
machine's folder, item by item, part by part."""
|
||||
@@ -83,7 +93,7 @@ def claim(c, user):
|
||||
machine, order = row['machine_id'], row['order_id']
|
||||
if row['state'] != 'queued' or order in blocked:
|
||||
continue
|
||||
cls = contraction(row, row['item_index'])
|
||||
cls = folder_class(row, row['item_index'])
|
||||
# A part without its class waits, and the parts after it with it.
|
||||
if busy.get(machine, 0) >= IN_FOLDER or not cls:
|
||||
blocked.add(order)
|
||||
|
||||
@@ -16,8 +16,9 @@ once, which lets exactly one more card through.
|
||||
clean CLEAN_EVERY_METRES printed since the last "clean" event.
|
||||
align ALIGN_AFTER_FILM_METRES printed since the last film change (a
|
||||
supply entry of "film") with no "align" event after it.
|
||||
supply a supply whose estimated stock is at or below the minimum Gestão set
|
||||
for that machine (no minimum, no alert).
|
||||
supply a supply whose estimated stock is at or below the machine's minimum:
|
||||
the one Gestão typed, or Dropstar's default for that supply (1 roll
|
||||
of film, 1 L of each ink, 5 kg of powder).
|
||||
|
||||
The supply estimate assumes each entry refills what was used since the one
|
||||
before: the use per metre is the quantity entered over the metres printed in
|
||||
@@ -40,6 +41,11 @@ SUPPLY_INTERVALS = 3
|
||||
SUPPLIES = {'film': ('Filme', 'rolo'), 'ink_c': ('Tinta ciano', 'L'), 'ink_m': ('Tinta magenta', 'L'),
|
||||
'ink_y': ('Tinta amarela', 'L'), 'ink_k': ('Tinta preta', 'L'), 'ink_w': ('Tinta branca', 'L'),
|
||||
'powder': ('Poliamida', 'kg')}
|
||||
# Dropstar's fixed minimums (2026-11-10): a machine with no minimum typed uses
|
||||
# these. Units match the supplies: rolls, litres and kilograms.
|
||||
DEFAULT_MINIMUMS = {'film': Decimal('1'), 'ink_c': Decimal('1'), 'ink_m': Decimal('1'),
|
||||
'ink_y': Decimal('1'), 'ink_k': Decimal('1'), 'ink_w': Decimal('1'),
|
||||
'powder': Decimal('5')}
|
||||
PARTS = {'cap': 'Cap', 'damper': 'Damper', 'head': 'Cabeça de impressão', 'wiper': 'Wiper', 'other': 'Outra peça'}
|
||||
EVENTS = {'clean': 'Limpeza', 'align': 'Alinhamento da cabeça', 'stop': 'Parada'}
|
||||
|
||||
@@ -130,8 +136,13 @@ def estimate(entries, metres_between, metres_since_last, minimum=None):
|
||||
'minimum': minimum}
|
||||
|
||||
|
||||
def minimum_for(minimums, item):
|
||||
"""The minimum typed for the machine, or Dropstar's default for that supply."""
|
||||
return minimums.get(item, DEFAULT_MINIMUMS.get(item))
|
||||
|
||||
|
||||
def supply_low(value):
|
||||
"""Whether an estimate is at or below the machine's minimum (no minimum, no alert)."""
|
||||
"""Whether an estimate is at or below the machine's minimum (typed or default)."""
|
||||
return bool(value) and value['minimum'] is not None and value['stock'] <= value['minimum']
|
||||
|
||||
|
||||
@@ -151,7 +162,8 @@ def supply_estimates(c, machine_id):
|
||||
continue
|
||||
printed = [printed_since(c, machine_id, row['created_at']) for row in rows]
|
||||
between = [printed[index - 1] - printed[index] for index in range(1, len(printed))]
|
||||
value = estimate([row['quantity'] for row in rows], between, printed[-1], minimums.get(item))
|
||||
value = estimate([row['quantity'] for row in rows], between, printed[-1],
|
||||
minimum_for(minimums, item))
|
||||
if value is not None:
|
||||
result[item] = value
|
||||
return result
|
||||
|
||||
@@ -93,7 +93,8 @@ def order_paid(c, order, origin):
|
||||
|
||||
|
||||
PRODUCTS = {'file': 'DTF Têxtil · folha montada', 'avulsa': 'DTF Têxtil · artes avulsas',
|
||||
'uvfile': 'DTF UV · folha montada', 'uv': 'DTF UV · artes avulsas'}
|
||||
'uvfile': 'DTF UV · folha montada', 'uv': 'DTF UV · artes avulsas',
|
||||
'premium': 'DTF Têxtil Premium · folha montada'}
|
||||
|
||||
|
||||
def quote_expired(c, quote, origin):
|
||||
|
||||
17
app/migrations/202611111200_premium-product.sql
Normal file
17
app/migrations/202611111200_premium-product.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
-- Front 3: the Premium product (Marcus, 2026-11-10), built and switched OFF
|
||||
-- until Dropstar prints the three test sheets and says "testado". The products
|
||||
-- CHECK is the inline constraint of dtf_local.products.id, which Postgres
|
||||
-- named products_id_check; widening a list is a new migration that drops and
|
||||
-- adds that one constraint (never schema.sql).
|
||||
ALTER TABLE dtf_local.products DROP CONSTRAINT IF EXISTS products_id_check;
|
||||
ALTER TABLE dtf_local.products ADD CONSTRAINT products_id_check
|
||||
CHECK (id IN ('file','avulsa','uvfile','uv','premium','tratamento'));
|
||||
|
||||
INSERT INTO dtf_local.products(id, enabled) VALUES ('premium', false)
|
||||
ON CONFLICT (id) DO NOTHING;
|
||||
|
||||
-- A coupon may also target the new product (the Site tab lists every mode).
|
||||
ALTER TABLE dtf_local.coupons DROP CONSTRAINT IF EXISTS coupons_product_check;
|
||||
ALTER TABLE dtf_local.coupons ADD CONSTRAINT coupons_product_check
|
||||
CHECK (product IN ('file','avulsa','uvfile','uv','premium'));
|
||||
|
||||
@@ -21,7 +21,8 @@ MARGIN = 4 * MM
|
||||
ROOM = WIDTH - 2 * MARGIN
|
||||
FONTS = {'F1': 'Helvetica-Bold', 'F2': 'Helvetica'}
|
||||
PRODUCTS = {'file': 'DTF Têxtil · folha montada', 'avulsa': 'DTF Têxtil · artes avulsas',
|
||||
'uvfile': 'DTF UV · folha montada', 'uv': 'DTF UV · artes avulsas'}
|
||||
'uvfile': 'DTF UV · folha montada', 'uv': 'DTF UV · artes avulsas',
|
||||
'premium': 'DTF Têxtil Premium · folha montada'}
|
||||
METHODS = {'pix': 'Pix', 'card': 'Cartão', 'cash': 'Dinheiro', 'credit': 'Crédito do cliente'}
|
||||
# Helvetica's widths for what the tables in printfile.py leave out.
|
||||
EXTRA = {'$': 556, '(': 333, ')': 333, '_': 556, '#': 556, '—': 1000, '@': 1015, '&': 667, '+': 584, "'": 191}
|
||||
|
||||
17
app/tiny.py
17
app/tiny.py
@@ -59,29 +59,34 @@ AUTH = 'https://accounts.tiny.com.br/realms/tiny/protocol/openid-connect'
|
||||
# Not TINY_PRODUCT_<MODE>: app/core/secrets.py reads any variable ending in
|
||||
# _FILE as a path to a secret file, and one product mode is called "file".
|
||||
PRODUCT_SETTINGS = {'file': 'TINY_PRODUCT_TEXTIL_FOLHA', 'avulsa': 'TINY_PRODUCT_TEXTIL_AVULSA',
|
||||
'uvfile': 'TINY_PRODUCT_UV_FOLHA', 'uv': 'TINY_PRODUCT_UV_AVULSA'}
|
||||
'uvfile': 'TINY_PRODUCT_UV_FOLHA', 'uv': 'TINY_PRODUCT_UV_AVULSA',
|
||||
'premium': 'TINY_PRODUCT_TEXTIL_PREMIUM'}
|
||||
# The common code prefix of a mode's SKUs ("DTFIMP.TX" for DTFIMP.TX.100CM,
|
||||
# the metre, and DTFIMP.TX.0010CM to DTFIMP.TX.0090CM). When set, it replaces
|
||||
# the mode's product id.
|
||||
SKU_SETTINGS = {'file': 'TINY_SKU_TEXTIL_FOLHA', 'avulsa': 'TINY_SKU_TEXTIL_AVULSA',
|
||||
'uvfile': 'TINY_SKU_UV_FOLHA', 'uv': 'TINY_SKU_UV_AVULSA'}
|
||||
'uvfile': 'TINY_SKU_UV_FOLHA', 'uv': 'TINY_SKU_UV_AVULSA',
|
||||
'premium': 'TINY_SKU_TEXTIL_PREMIUM'}
|
||||
# Or a SKU per 10 cm ("DTFIMP.UV.010CM"), alone (2,30 m is 23 of it) or after
|
||||
# a metre SKU ("DTFIMP.UV.1MT"): 2,30 m is 2 metres and 3 of the 10 cm.
|
||||
STEP_SETTINGS = {'file': 'TINY_SKU10_TEXTIL_FOLHA', 'avulsa': 'TINY_SKU10_TEXTIL_AVULSA',
|
||||
'uvfile': 'TINY_SKU10_UV_FOLHA', 'uv': 'TINY_SKU10_UV_AVULSA'}
|
||||
'uvfile': 'TINY_SKU10_UV_FOLHA', 'uv': 'TINY_SKU10_UV_AVULSA',
|
||||
'premium': 'TINY_SKU10_TEXTIL_PREMIUM'}
|
||||
METRE_SETTINGS = {'file': 'TINY_SKU_METRO_TEXTIL_FOLHA', 'avulsa': 'TINY_SKU_METRO_TEXTIL_AVULSA',
|
||||
'uvfile': 'TINY_SKU_METRO_UV_FOLHA', 'uv': 'TINY_SKU_METRO_UV_AVULSA'}
|
||||
'uvfile': 'TINY_SKU_METRO_UV_FOLHA', 'uv': 'TINY_SKU_METRO_UV_AVULSA',
|
||||
'premium': 'TINY_SKU_METRO_TEXTIL_PREMIUM'}
|
||||
# Dropstar's own catalogue (checked against its Tiny export, 2026-10-14): Têxtil
|
||||
# as DTFIMP.TX.100CM per metre and DTFIMP.TX.0010CM to 0090CM for the rest, UV
|
||||
# as DTFIMP.UV.1MT per metre and DTFIMP.UV.010CM per 10 cm, the ready sheet and
|
||||
# loose artwork alike. The settings above only override these.
|
||||
SKU_DEFAULTS = {'file': 'DTFIMP.TX', 'avulsa': 'DTFIMP.TX'}
|
||||
SKU_DEFAULTS = {'file': 'DTFIMP.TX', 'avulsa': 'DTFIMP.TX', 'premium': 'DTFP.TX'}
|
||||
STEP_DEFAULTS = {'uvfile': 'DTFIMP.UV.010CM', 'uv': 'DTFIMP.UV.010CM'}
|
||||
METRE_DEFAULTS = {'uvfile': 'DTFIMP.UV.1MT', 'uv': 'DTFIMP.UV.1MT'}
|
||||
PRODUCTS = {'file': 'DTF Têxtil 57 cm · folha montada',
|
||||
'avulsa': 'DTF Têxtil 57 cm · artes avulsas',
|
||||
'uvfile': 'DTF UV 27 cm · folha montada',
|
||||
'uv': 'DTF UV 27 cm · artes avulsas'}
|
||||
'uv': 'DTF UV 27 cm · artes avulsas',
|
||||
'premium': 'DTF Têxtil Premium 57 cm · folha montada'}
|
||||
# How far back to look for an order a previous delivery may already have made.
|
||||
SEARCH_DAYS = 7
|
||||
# A "ready" event can come after corrections; it normally knows the Tiny id.
|
||||
|
||||
@@ -49,7 +49,7 @@ server {
|
||||
# Always revalidate HTML/JS/CSS after a deployment. Without this, a browser
|
||||
# can pair a new Kanban page with a cached older script after a rollout.
|
||||
# The Site's product pages and cart are addresses of the same page (web/site-pages.js).
|
||||
location ~ ^/(arquivo-por-metro|artes-avulsas|uv-arquivo-por-metro|uv-artes-avulsas|carrinho|pagamento|pagamento/pix)/?$ {
|
||||
location ~ ^/(arquivo-por-metro|artes-avulsas|uv-arquivo-por-metro|uv-artes-avulsas|premium|carrinho|pagamento|pagamento/pix)/?$ {
|
||||
expires -1;
|
||||
try_files /index.html =404;
|
||||
}
|
||||
|
||||
@@ -3,22 +3,35 @@
|
||||
Run against the local stack: SITE_BASE_URL=http://site SITE_HOST_HEADER=localhost
|
||||
python -m tests.site_admin_test
|
||||
"""
|
||||
import io
|
||||
import secrets
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from uuid import uuid4
|
||||
|
||||
from PIL import Image, ImageDraw
|
||||
|
||||
from app.core import db
|
||||
from tests.print_file_test import artwork
|
||||
from tests.smoke_test import Client, item_spec, upload_bytes
|
||||
|
||||
PASSWORD = 'senha-de-teste-123'
|
||||
UV = 'uv'
|
||||
PREMIUM = 'premium'
|
||||
|
||||
|
||||
def quote(client, item, mail):
|
||||
def premium_sheet():
|
||||
"""A 57 cm wide sheet above 96 DPI at that width, so the server accepts it."""
|
||||
image = Image.new('RGBA', (2400, 800), (0, 0, 0, 0))
|
||||
ImageDraw.Draw(image).rectangle([40, 40, 2360, 760], fill=(220, 30, 60, 255))
|
||||
out = io.BytesIO()
|
||||
image.save(out, 'PNG', dpi=(300, 300))
|
||||
return out.getvalue()
|
||||
|
||||
|
||||
def quote(client, item, mail, expected=200):
|
||||
return client.call('/quotes', {'request_key': str(uuid4()),
|
||||
'customer': {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': mail},
|
||||
'items': [item], 'freight': {'service': 'pickup'}})
|
||||
'items': [item], 'freight': {'service': 'pickup'}}, expected=expected)
|
||||
|
||||
|
||||
def run():
|
||||
@@ -34,9 +47,30 @@ def run():
|
||||
prices, user = [], None
|
||||
try:
|
||||
products = manager.call('/operator/site/products')['products']
|
||||
assert {product['id'] for product in products} == {'file', 'avulsa', 'uvfile', 'uv', 'tratamento'}
|
||||
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)
|
||||
|
||||
# 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)
|
||||
assert premium_entry['enabled'] is False, premium_entry
|
||||
assert premium_entry['title'] == 'Têxtil Premium · 8 passadas', premium_entry
|
||||
assert client.call('/session')['products'][PREMIUM]['enabled'] is False
|
||||
premium_item = {**item_spec(PREMIUM, '1', 0, upload_bytes(
|
||||
client, premium_sheet(), name='LOCAL-SITE-PREMIUM.png')),
|
||||
'quality_status': 'warning', 'quality_acknowledged': True}
|
||||
refused = quote(client, premium_item, mail, expected=422)
|
||||
assert refused['detail'] == 'Este produto não está à venda agora.', refused
|
||||
manager.call(f'/operator/site/products/{PREMIUM}', {'enabled': True})
|
||||
assert client.call('/session')['products'][PREMIUM]['enabled'] is True
|
||||
created = quote(client, premium_item, mail)
|
||||
assert created['status'] == 'approved', created
|
||||
approved = client.call('/quotes/' + created['id'])['approved']
|
||||
assert approved['items'][0]['mode'] == PREMIUM, approved
|
||||
assert approved['items'][0]['unit_cents'] == 3990, approved
|
||||
assert approved['total_cents'] == 3990, approved
|
||||
manager.call(f'/operator/site/products/{PREMIUM}', {'enabled': False})
|
||||
|
||||
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}
|
||||
@@ -123,13 +157,15 @@ def run():
|
||||
staff.call(f'/operator/site/products/{UV}', {'enabled': True}, expected=403)
|
||||
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, schedules and cancels prices,'
|
||||
' charges the new price, and refuses a non-manage profile')
|
||||
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')
|
||||
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 user:
|
||||
try:
|
||||
manager.call('/operator/users/' + str(user['id']) + '/delete', {}, expected=200)
|
||||
|
||||
@@ -131,7 +131,7 @@ def item_spec(mode, metres, grade, uid):
|
||||
return {'mode':mode,'metres':str(metres),'grade':grade,'uploads':[uid],
|
||||
'production':{'version':2,'film_width_cm':film_width,'height_cm':length_cm,
|
||||
'sources':[{'upload_id':uid,
|
||||
'kind':'sheet' if mode in ('file','uvfile') else 'artwork',
|
||||
'kind':'sheet' if mode in ('file','uvfile','premium') else 'artwork',
|
||||
'width_cm':film_width,'length_cm':length_cm,'copies':1,
|
||||
'rotation_degrees':0,'mirrored':False,'measurement':'customer'}],
|
||||
'placements':[{'source_index':0,'copy_index':0,'x_cm':0,'y_cm':0,
|
||||
|
||||
26
tests/test_hotfolder.py
Normal file
26
tests/test_hotfolder.py
Normal file
@@ -0,0 +1,26 @@
|
||||
"""The machine hot folder class (Fase 2, front 3), without a database."""
|
||||
import unittest
|
||||
|
||||
from app.hotfolder import PREMIUM, contraction, folder_class
|
||||
|
||||
|
||||
def order(mode, stroke_class='C2', chosen=None):
|
||||
return {'snapshot': {'items': [{'mode': mode, 'stroke_class': stroke_class}]},
|
||||
'contraction': {'0': {'class': chosen}} if chosen else {}}
|
||||
|
||||
|
||||
class FolderClassTest(unittest.TestCase):
|
||||
def test_premium_always_goes_to_its_own_folder(self):
|
||||
# Marcus, 2026-11-10: every premium item, whatever its contraction class.
|
||||
self.assertEqual(folder_class(order('premium', 'C3'), 0), PREMIUM)
|
||||
self.assertEqual(folder_class(order('premium', 'C1', chosen='C2'), 0), PREMIUM)
|
||||
|
||||
def test_a_recorded_contraction_class_still_wins_for_other_products(self):
|
||||
self.assertEqual(folder_class(order('file', 'C1', chosen='C2'), 0), 'C2')
|
||||
self.assertEqual(folder_class(order('file'), 0), 'C2')
|
||||
self.assertIsNone(contraction(order('file', None), 0))
|
||||
self.assertIsNone(folder_class(order('file', None), 0))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -2,8 +2,8 @@
|
||||
import unittest
|
||||
from decimal import Decimal
|
||||
|
||||
from app.machine_log import (ALIGN_AFTER_FILM_METRES, CLEAN_EVERY_METRES, estimate,
|
||||
one_decimal, supply_low)
|
||||
from app.machine_log import (ALIGN_AFTER_FILM_METRES, CLEAN_EVERY_METRES, DEFAULT_MINIMUMS,
|
||||
estimate, minimum_for, one_decimal, supply_low)
|
||||
|
||||
|
||||
class EstimateTest(unittest.TestCase):
|
||||
@@ -38,6 +38,22 @@ class EstimateTest(unittest.TestCase):
|
||||
self.assertEqual(CLEAN_EVERY_METRES, Decimal('10'))
|
||||
self.assertEqual(ALIGN_AFTER_FILM_METRES, Decimal('20'))
|
||||
|
||||
def test_a_machine_without_typed_minimums_alerts_at_dropstars_defaults(self):
|
||||
# Marcus, 2026-11-10: 1 roll of film, 1 L of each ink, 5 kg of powder.
|
||||
self.assertEqual(DEFAULT_MINIMUMS, {'film': Decimal('1'), 'ink_c': Decimal('1'),
|
||||
'ink_m': Decimal('1'), 'ink_y': Decimal('1'),
|
||||
'ink_k': Decimal('1'), 'ink_w': Decimal('1'),
|
||||
'powder': Decimal('5')})
|
||||
for item, default in DEFAULT_MINIMUMS.items():
|
||||
with self.subTest(item=item):
|
||||
minimum = minimum_for({}, item)
|
||||
self.assertEqual(minimum, default)
|
||||
value = estimate([Decimal('1'), Decimal('1')], [Decimal('10')],
|
||||
Decimal('9'), minimum)
|
||||
self.assertTrue(supply_low(value))
|
||||
# A minimum Gestão typed still wins over the default.
|
||||
self.assertEqual(minimum_for({'film': Decimal('0')}, 'film'), Decimal('0'))
|
||||
|
||||
|
||||
class AlertTextTest(unittest.TestCase):
|
||||
def test_one_decimal_uses_a_comma(self):
|
||||
|
||||
@@ -34,8 +34,9 @@ class PricingTests(unittest.TestCase):
|
||||
|
||||
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})
|
||||
# art; UV R$ 79,90 and R$ 89,90. Premium R$ 39,90 (2026-11-10).
|
||||
self.assertEqual(PRICES, {'file': 1990, 'avulsa': 2190, 'uvfile': 7990, 'uv': 8990,
|
||||
'premium': 3990})
|
||||
self.assertEqual(price('avulsa', '2.75', 90)['total_cents'], 6132)
|
||||
|
||||
def test_the_grade_never_changes_the_price(self):
|
||||
|
||||
@@ -24,7 +24,8 @@ PAID = {'order_id': 'b6f1c0de-0000-4000-8000-000000000001', 'number': 42, 'event
|
||||
'state': 'SP', 'postal_code': '14400000'},
|
||||
'total_cents': 8472}}
|
||||
PRODUCTS = {'TINY_PRODUCT_TEXTIL_FOLHA': '101', 'TINY_PRODUCT_TEXTIL_AVULSA': '102',
|
||||
'TINY_PRODUCT_UV_FOLHA': '103', 'TINY_PRODUCT_UV_AVULSA': '104', 'TINY_FORMA_ENVIO_RETIRADA': '77'}
|
||||
'TINY_PRODUCT_UV_FOLHA': '103', 'TINY_PRODUCT_UV_AVULSA': '104',
|
||||
'TINY_PRODUCT_TEXTIL_PREMIUM': '105', 'TINY_FORMA_ENVIO_RETIRADA': '77'}
|
||||
PICKUP = {**PAID, 'order': {**PAID['order'], 'destination': None, 'freight': {'service': 'pickup', 'total_cents': 0}}}
|
||||
READY = {'order_id': PAID['order_id'], 'number': 42, 'event': 'ready', 'reason': '', 'order': PICKUP['order']}
|
||||
|
||||
@@ -221,7 +222,7 @@ class TinyTests(FakeTinyCase):
|
||||
from app.tiny import check
|
||||
results = check(auth=FakeAuth(), transport=httpx.MockTransport(self.handler))
|
||||
self.assertEqual(set(results.values()), {'ok'})
|
||||
self.assertEqual(len(results), 7)
|
||||
self.assertEqual(len(results), 8)
|
||||
self.assertTrue(all(method == 'GET' for method, _ in self.calls))
|
||||
self.products['103']['situacao'] = 'I'
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_UV_AVULSA': ''}):
|
||||
@@ -794,6 +795,9 @@ class DefaultSkuTests(unittest.TestCase):
|
||||
self.assertEqual(tiny.mode_codes('file'), tiny.sku_codes('DTFIMP.TX'))
|
||||
self.assertEqual(tiny.mode_codes('avulsa'), tiny.sku_codes('DTFIMP.TX'))
|
||||
self.assertEqual(tiny.mode_codes('uv'), ['DTFIMP.UV.1MT', 'DTFIMP.UV.010CM'])
|
||||
# Premium's own catalogue: DTFP.TX.100CM per metre (front 3).
|
||||
self.assertEqual(tiny.mode_codes('premium'), tiny.sku_codes('DTFP.TX'))
|
||||
self.assertIn('DTFP.TX.100CM', tiny.mode_codes('premium'))
|
||||
self.assertEqual(tiny.required_settings(), ['TINY_CLIENT_ID', 'TINY_CLIENT_SECRET', 'TINY_REDIRECT_URI'])
|
||||
with mock.patch.dict(os.environ, {'TINY_SKU10_UV_FOLHA': 'UV.X'}):
|
||||
self.assertEqual(tiny.mode_codes('uvfile'), ['UV.X'])
|
||||
|
||||
@@ -97,7 +97,8 @@
|
||||
PRECO[mode]=product.unit_cents/100;
|
||||
FAIXAS[mode]=product.bands||[];
|
||||
const card=document.querySelector('button.ec[data-modo="'+mode+'"]');
|
||||
if(card&&!product.enabled)card.hidden=true;
|
||||
// Premium starts hidden in the HTML and only appears once enabled.
|
||||
if(card)card.hidden=!product.enabled;
|
||||
}
|
||||
document.querySelectorAll('[data-preco]').forEach(el=>{
|
||||
const product=session.products[el.dataset.preco];
|
||||
|
||||
@@ -75,6 +75,7 @@ h1 em{font-style:normal;color:var(--laranja)}
|
||||
.escolha{display:grid;grid-template-columns:repeat(4,1fr);gap:14px;margin-top:24px;
|
||||
align-items:stretch}
|
||||
.escolha .ec{display:flex;flex-direction:column}
|
||||
.escolha .ec[hidden]{display:none}
|
||||
.escolha .ec .in{flex:1}
|
||||
@media(max-width:1000px){.escolha{grid-template-columns:repeat(2,1fr)}}
|
||||
@media(max-width:600px){.escolha{grid-template-columns:1fr}}
|
||||
@@ -815,6 +816,15 @@ h2 em{font-style:normal;color:var(--laranja)}
|
||||
<span class="ec-go">Enviar artes de UV</span>
|
||||
</div>
|
||||
</button>
|
||||
<button class="ec p" data-modo="premium" hidden>
|
||||
<div class="ec-top"><span class="ec-kind">DTF TÊXTIL PREMIUM · 57 CM</span></div>
|
||||
<h3>Premium · 8 passadas</h3>
|
||||
<p>Branco no máximo e cor mais fechada, para marca própria.</p>
|
||||
<div class="ec-pe">
|
||||
<div class="ec-preco"><b data-preco="premium">R$ 39,90</b><span>por metro</span></div>
|
||||
<span class="ec-go">Enviar minha folha</span>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -10,11 +10,11 @@ sessionStorage.removeItem('dtf-operator');
|
||||
const FLOW=['rec','tra','imp','rev','fin'];
|
||||
const FORMER_STATES={fil:'Fila de impressão'};
|
||||
const stateName=s=>board.states[s]||FORMER_STATES[s]||s;
|
||||
const PRODUCT={file:'DTF Têxtil · folha montada',avulsa:'DTF Têxtil · artes avulsas',uvfile:'DTF UV · folha montada',uv:'DTF UV · artes avulsas'};
|
||||
const PRODUCT={file:'DTF Têxtil · folha montada',avulsa:'DTF Têxtil · artes avulsas',uvfile:'DTF UV · folha montada',uv:'DTF UV · artes avulsas',premium:'DTF Têxtil Premium · folha montada'};
|
||||
// Loose art the Site split by stroke (item 17): each sheet is an item of its own.
|
||||
const productName=item=>PRODUCT[item.mode]+(item.split?' · folha '+item.split.part+' de '+item.split.of+
|
||||
', '+(item.stroke_class==='C3'?'chapado':'traço fino'):'');
|
||||
const SHORT={file:'Têxtil folha',avulsa:'Têxtil avulsa',uvfile:'UV folha',uv:'UV avulsa'};
|
||||
const SHORT={file:'Têxtil folha',avulsa:'Têxtil avulsa',uvfile:'UV folha',uv:'UV avulsa',premium:'Premium'};
|
||||
const EVENTS={payment_approved:'Pagamento aprovado',production_started:'Produção iniciada',correction_needed:'Correção necessária',ready:'Pedido pronto',cancelled:'Pedido cancelado'};
|
||||
// Payment outcomes are recorded by the API in English; operators read Portuguese.
|
||||
function outcomeText(outcome){
|
||||
@@ -427,7 +427,7 @@ async function fetchInto(dir,file){
|
||||
await writeWhole(dir,file.name,r.body);
|
||||
}
|
||||
|
||||
// The machines' hot folders (item 10): 3. Imprimindo/<máquina>/<C1|C2|C3>/.
|
||||
// The machines' hot folders (item 10): 3. Imprimindo/<máquina>/<C1|C2|C3|PREMIUM>/.
|
||||
// The server says what this computer writes now (claimed for it alone, two
|
||||
// parts at most per machine); a written part gone from its folder was taken
|
||||
// by FlexiPRINT, and is never written again; a withdrawn one, from a card that
|
||||
@@ -757,7 +757,7 @@ const FILTER_TESTS={
|
||||
site:o=>o.origin==='site',
|
||||
dropflow:o=>o.origin==='dropflow',
|
||||
atendimento:o=>o.origin==='atendimento',
|
||||
textil:o=>o.snapshot.items.some(i=>i.mode==='file'||i.mode==='avulsa'),
|
||||
textil:o=>o.snapshot.items.some(i=>i.mode==='file'||i.mode==='avulsa'||i.mode==='premium'),
|
||||
uv:o=>o.snapshot.items.some(i=>i.mode==='uvfile'||i.mode==='uv'),
|
||||
entrega:o=>!!o.snapshot.destination,
|
||||
retirada:o=>!o.snapshot.destination,
|
||||
@@ -1116,6 +1116,7 @@ function card(order,place){
|
||||
const meta=node('span',undefined,'cmeta');meta.append(node('span',productLine(s.items)));
|
||||
const special=specialDelivery(s);
|
||||
if(special){const tag=node('span',special,'origin');tag.title=special;meta.append(tag);}
|
||||
if(s.items.some(i=>i.mode==='premium'))meta.append(badge('Premium','','DTF Têxtil Premium: 8 passadas, branco no máximo'));
|
||||
if(order.machine){const m=node('span',order.machine.name,'mach'+(mine?' mine':''));m.title=mine?'Sua máquina':'Máquina';meta.append(m);}
|
||||
meta.append(node('b',metres(orderMetres(order)),'mtr'));
|
||||
info.append(row,name,meta);
|
||||
@@ -1440,6 +1441,7 @@ function renderPanel(order){
|
||||
sub.append(badge('Nota '+s.grade_flags.aviso+': conferir a arte','warn',
|
||||
'A nota da arte ficou abaixo do limite configurado: confira antes de imprimir'));
|
||||
if(isTest(order))sub.append(badge('Teste','','Pedido de teste: sem pagamento, não vai ao Tiny'));
|
||||
if(s.items.some(i=>i.mode==='premium'))sub.append(badge('Premium','','DTF Têxtil Premium: 8 passadas, branco no máximo'));
|
||||
if(stalled(order)&&!order.cancelled_at)sub.append(badge('Parado há '+hoursSince(order.updated_at)+' h','bad','Sem mudar de etapa desde '+when(order.updated_at)));
|
||||
const steps=node('ol',undefined,'stepper');steps.setAttribute('aria-label','Etapas');
|
||||
const at=FLOW.indexOf(order.state);
|
||||
@@ -2824,7 +2826,11 @@ async function openMachineSheet(machineId){
|
||||
box.append(field('Preço de compra (R$)',price),field('Data de instalação',installed));
|
||||
for(const [item,[label,unit]] of Object.entries(data.catalog.supplies)){
|
||||
const input=node('input');input.type='number';input.min='0';input.step='0.001';input.inputMode='decimal';
|
||||
input.value=data.minimums[item]!==null&&data.minimums[item]!==undefined?Number(data.minimums[item]).toString():'';
|
||||
// Dropstar's fixed minimums are the defaults: a machine with none typed
|
||||
// shows and uses them until Gestão changes them.
|
||||
const typed=data.minimums[item], fallback=data.default_minimums?.[item];
|
||||
input.value=typed!==null&&typed!==undefined?Number(typed).toString()
|
||||
:fallback!==null&&fallback!==undefined?Number(fallback).toString():'';
|
||||
minimums[item]=input;
|
||||
box.append(field('Mínimo de '+label.toLowerCase()+' ('+unit+')',input));
|
||||
}
|
||||
|
||||
@@ -51,12 +51,14 @@ const MODOS={
|
||||
zt:'Arraste sua folha de UV aqui', zs:'PNG ou PDF com fundo transparente · 27 cm de largura'},
|
||||
uv: {tit:'Artes avulsas · UV', lg:'Adesivo UV · 27 cm', larg:27, multi:true,
|
||||
zt:'Arraste suas artes de UV',
|
||||
zs:'PNG com fundo transparente · informe a largura de cada arte'}
|
||||
zs:'PNG com fundo transparente · informe a largura de cada arte'},
|
||||
premium:{tit:'DTF Premium', lg:'DTF têxtil premium · 57 cm', larg:57, multi:true, folha:true,
|
||||
zt:'Arraste sua folha montada aqui', zs:'PNG ou PDF com fundo transparente · 57 cm de largura'}
|
||||
};
|
||||
// Preço único por produto (Dropstar, 23/10/2026). A nota da arte continua na
|
||||
// tela, para o cliente entender o arquivo dele, mas não mexe no preço.
|
||||
// O servidor cobra o mesmo (app/core/pricing.py, conferido em tests/test_pricing.py).
|
||||
const PRECO={file:19.90, avulsa:21.90, uvfile:79.90, uv:89.90};
|
||||
const PRECO={file:19.90, avulsa:21.90, uvfile:79.90, uv:89.90, premium:39.90};
|
||||
// Faixas por metragem (front 8.2): o preço do metro depende do total do
|
||||
// produto no pedido, não de cada item. Vem do servidor (/api/session), que
|
||||
// cobra o mesmo (app/catalog.py band_price).
|
||||
|
||||
@@ -46,7 +46,8 @@ function pintaModo(){
|
||||
// dá para voltar atrás sem recomeçar o pedido.
|
||||
function pintaTipoEnvio(){
|
||||
const el=$('tipoEnvio'); if(!el) return;
|
||||
el.hidden=!modo;
|
||||
// A product without its loose-art counterpart (Premium) has nothing to choose.
|
||||
el.hidden=!modo || (ehFolha() && !PAR[modo]);
|
||||
if(el.hidden) return;
|
||||
const folha = ehFolha() ? modo : PAR[modo];
|
||||
const avulsa = ehFolha() ? PAR[modo] : modo;
|
||||
@@ -80,7 +81,7 @@ function recusaFolha(x, md){
|
||||
'<button type="button" id="usarAvulsa">Enviar como '+MODOS[destino].tit.toLowerCase()+'</button>');
|
||||
const botao=$('usarAvulsa');
|
||||
if(botao) botao.addEventListener('click',()=>{
|
||||
avisoTipo(''); trocaTipo(PAR[modo]); sel([arquivo]);
|
||||
avisoTipo(''); trocaTipo(destino); sel([arquivo]);
|
||||
});
|
||||
}
|
||||
document.querySelectorAll('#tipoEnvio .cam').forEach(b=>b.addEventListener('click',()=>{
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
addresses. Loaded in <head> so the right page is the first one painted;
|
||||
site-steps.js does the navigation. */
|
||||
const PAGINAS={file:'/arquivo-por-metro', avulsa:'/artes-avulsas',
|
||||
uvfile:'/uv-arquivo-por-metro', uv:'/uv-artes-avulsas'};
|
||||
uvfile:'/uv-arquivo-por-metro', uv:'/uv-artes-avulsas',
|
||||
premium:'/premium'};
|
||||
const CARRINHO='/carrinho', PAGAMENTO='/pagamento', PAGAMENTO_PIX='/pagamento/pix';
|
||||
function paginaDe(caminho){
|
||||
caminho=caminho.replace(/\/+$/,'')||'/';
|
||||
|
||||
Reference in New Issue
Block a user