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>
This commit is contained in:
@@ -14,10 +14,10 @@ from fastapi import APIRouter, Depends, HTTPException
|
||||
from psycopg.errors import UniqueViolation
|
||||
from psycopg.types.json import Jsonb
|
||||
|
||||
from .. import catalog
|
||||
from .. import catalog, grade_rules
|
||||
from ..core import db
|
||||
from ..core.auth import audit, can
|
||||
from ..core.models import CouponNew, CouponUpdate, SitePriceNew, SiteProductToggle
|
||||
from ..core.models import CouponNew, CouponUpdate, GradeRules, SitePriceNew, SiteProductToggle
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -233,3 +233,30 @@ def delete_coupon(coupon_id: UUID, user=Depends(can('manage'))):
|
||||
raise HTTPException(404, 'Cupom não encontrado.')
|
||||
audit('site_coupon_deleted', coupon=str(coupon_id), code=row['code'], operator=user)
|
||||
return {'ok': True}
|
||||
|
||||
|
||||
@router.get('/api/operator/site/grade-rules')
|
||||
def site_grade_rules(user=Depends(can('manage'))):
|
||||
with db.connect() as c:
|
||||
rules = grade_rules.current_rules(c)
|
||||
offered = catalog.treatment_offered(c)
|
||||
return {'aviso': rules.get('aviso'), 'tratamento': rules.get('tratamento'),
|
||||
'treatment_offered': offered}
|
||||
|
||||
|
||||
@router.post('/api/operator/site/grade-rules')
|
||||
def save_grade_rules(body: GradeRules, user=Depends(can('manage'))):
|
||||
if body.aviso is not None and body.tratamento is not None and body.tratamento > body.aviso:
|
||||
raise HTTPException(422, 'A regra do tratamento precisa ser menor ou igual à do aviso.')
|
||||
with db.connect() as c:
|
||||
for action, below in (('aviso', body.aviso), ('tratamento', body.tratamento)):
|
||||
if below is None:
|
||||
c.execute('DELETE FROM dtf_local.grade_rules WHERE action=%s', (action,))
|
||||
else:
|
||||
c.execute('''INSERT INTO dtf_local.grade_rules(action,below,updated_by,updated_at)
|
||||
VALUES(%s,%s,%s,now())
|
||||
ON CONFLICT (action) DO UPDATE SET below=EXCLUDED.below,
|
||||
updated_by=EXCLUDED.updated_by, updated_at=now()''',
|
||||
(action, below, user))
|
||||
audit('site_grade_rules_changed', aviso=body.aviso, tratamento=body.tratamento, operator=user)
|
||||
return {'ok': True}
|
||||
|
||||
Reference in New Issue
Block a user