feat: Premium built and switched off; default machine minimums (front 3, Marcus 10/11)

Premium (8 passadas, R$ 39,90/m, SKU DTFP.TX.100CM) is a fifth textile
ready-sheet product: priced on the server and the Site, a hidden fifth card,
a PREMIUM hot-folder class, its Tiny SKU, and a products row created
disabled by a migration until Dropstar says 'testado'. A machine with no
typed minimum now alerts at Dropstar's fixed minimums: 1 roll of film, 1 L
of each ink, 5 kg of powder.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-11-11 10:52:08 -03:00
parent e6197d6e40
commit a9a4b61d99
25 changed files with 202 additions and 49 deletions

View File

@@ -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,

View File

@@ -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):

View File

@@ -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:

View File

@@ -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:
@@ -396,7 +396,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)
@@ -409,7 +409,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

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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):

View 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'));

View File

@@ -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}

View File

@@ -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.