Files
dtf-system/app/grade_rules.py
Cauê Faleiros 272755d2bc feat: the art grade becomes configurable, off by default (front 8.5)
Gestão sets in the Site tab below which grade the designer is warned and
below which the designer treatment is required (only while it is offered).
The decision is stored with the approved quote, so a later change never
rewrites old orders; the card shows 'Nota N: conferir a arte', the Site
forces the treatment box with the reason. With no rule nothing changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-11-09 16:13:30 -03:00

35 lines
1.4 KiB
Python

"""What the art grade decides, set in the Kanban's Site tab (Fase 2, front 8.5).
With no rule nothing changes anywhere. An item triggers a rule when its grade
is below the rule's `below`; the order's worst item decides. `aviso` flags the
order for the designer; `tratamento` makes the designer's treatment required,
but only while it is offered (enabled and priced above zero).
"""
def current_rules(c) -> dict:
"""{'aviso': 70, 'tratamento': 50} for the rows that exist."""
return {row['action']: row['below'] for row in
c.execute('SELECT action, below FROM dtf_local.grade_rules').fetchall()}
def triggered(rules: dict, items, treatment_offered: bool) -> dict:
"""The rules the order's worst item triggers: {'aviso': N}, maybe with
'tratamento': N. N is the worst grade; empty when no rule applies."""
grades = [item.get('grade') for item in items if item.get('grade') is not None]
if not grades:
return {}
worst = min(grades)
flags = {}
if 'aviso' in rules and worst < rules['aviso']:
flags['aviso'] = worst
if treatment_offered and 'tratamento' in rules and worst < rules['tratamento']:
flags['tratamento'] = worst
return flags
def treatment_message(grade: int) -> str:
"""The refusal the customer sees when the treatment is required."""
return (f'Sua arte tem nota {grade}: para imprimir com qualidade, o tratamento '
'pelo designer é obrigatório neste pedido.')