diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 473e99a..1bfbff0 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -101,7 +101,7 @@ jobs: # the generator's geometry. The provider suites use a fake transport: they # prove the documented contract, not the integration. - name: Print-file geometry and provider adapters - run: $COMPOSE exec -T api python -m unittest tests.test_printfile tests.test_printpng tests.test_mercadopago tests.test_tiny tests.test_cnpj tests.test_payment_messages tests.test_jadlog tests.test_correios tests.test_quote_review tests.test_moves tests.test_large_files tests.test_grade_check tests.test_schema tests.test_customer_document tests.test_mail_html tests.test_layout_rules tests.test_proof_cut tests.test_proof_render tests.test_sheet_trim tests.test_prumo tests.test_speed tests.test_printpng_validate tests.test_machine_log tests.test_machine_stats tests.test_label tests.test_observability tests.test_worker_drain tests.test_db_outage tests.test_health -v + run: $COMPOSE exec -T api python -m unittest tests.test_printfile tests.test_printpng tests.test_mercadopago tests.test_tiny tests.test_cnpj tests.test_payment_messages tests.test_jadlog tests.test_correios tests.test_quote_review tests.test_moves tests.test_large_files tests.test_grade_check tests.test_schema tests.test_customer_document tests.test_mail_html tests.test_layout_rules tests.test_proof_cut tests.test_proof_render tests.test_sheet_trim tests.test_one_machine tests.test_prumo tests.test_speed tests.test_printpng_validate tests.test_machine_log tests.test_machine_stats tests.test_label tests.test_observability tests.test_worker_drain tests.test_db_outage tests.test_health -v - name: Runtime and retention regressions run: | diff --git a/app/core/models.py b/app/core/models.py index 485371c..8b0951e 100644 --- a/app/core/models.py +++ b/app/core/models.py @@ -165,6 +165,19 @@ class Split(StrictModel): of: int = Field(ge=2, le=10, strict=True) +UV_MODES = ('uvfile', 'uv') +ONE_MACHINE = ('Esse produto é impresso em outra máquina e precisa de um pedido separado. ' + 'Finalize este pedido e faça um novo com ele.') + + +def check_one_machine(items): + """One order, one machine (Marcus, 2026-11-26): UV and textile never share + an order, since its card goes to one machine. Basic and premium textile + print on the same machines and may.""" + if len({item.mode in UV_MODES for item in items}) > 1: + raise ValueError(ONE_MACHINE) + + def check_splits(items): """Every split group has each of its parts once, of one product.""" groups = {} @@ -309,6 +322,7 @@ class QuoteRequest(StrictModel): @model_validator(mode='after') def splits_complete(self): check_splits(self.items) + check_one_machine(self.items) return self @model_validator(mode='after') @@ -399,6 +413,7 @@ class Review(StrictModel): @model_validator(mode='after') def splits_complete(self): check_splits(self.items) + check_one_machine(self.items) return self class Pay(StrictModel): diff --git a/tests/smoke_test.py b/tests/smoke_test.py index 2fc6ea2..15f0fe8 100644 --- a/tests/smoke_test.py +++ b/tests/smoke_test.py @@ -196,12 +196,16 @@ def run(): print('PASS: multipart resume, incomplete rejection, immutable completion, ownership, private/downloaded bytes') # Above QUOTE_AUTO_MAX_METRES (50 m by default), so a person reviews it. - items=[item_spec(m,'13',90,uid) for m in ('file','avulsa','uvfile','uv')] + # One order, one machine (Marcus, 2026-11-26): the two textile products; + # UV goes in an order of its own. + items=[item_spec(m,'26',90,uid) for m in ('file','avulsa')] draft={'request_key':str(uuid4()),'customer':{'cnpj':'11222333000181','zap':'11999999999','mail':'local-smoke@example.test'}, 'items':items,'freight':{'service':'mock-standard','postal_code':'14400000'}, 'destination':{'recipient':'Local Smoke Ltda','street':'Rua de Teste','number':'100', 'district':'Centro','city':'Franca','state':'SP','postal_code':'14400000'}} client.call('/quotes',{**draft,'total_cents':1},expected=422) + mixed_cart=client.call('/quotes',{**draft,'items':[items[0],item_spec('uvfile','13',90,uid)]},expected=422)['detail'] + assert any('outra máquina' in str(e.get('msg','')) for e in mixed_cart), mixed_cart # Freight quoted by CEP alone cannot ship: the address is required, must be # the quoted CEP, and a pickup order takes none. client.call('/quotes',{**draft,'destination':None},expected=422) @@ -237,8 +241,8 @@ def run(): corrected=[{**items[0],'metres':'1.01','grade':0},*items[1:]] approved=client.call('/operator/quotes/'+qid+'/approve',{'items':corrected},operator=True) assert approved['items'][0]['total_cents']==2189 and approved['items'][0]['grade']==0 - assert [i['unit_cents'] for i in approved['items'][1:]]==[2190,7990,8990] - assert approved['total_cents']==2189+28470+103870+116870+int(os.environ.get('MOCK_FREIGHT_CENTS','1500')) + assert [i['unit_cents'] for i in approved['items'][1:]]==[2190] + assert approved['total_cents']==2189+56940+int(os.environ.get('MOCK_FREIGHT_CENTS','1500')) assert approved['destination']=={**draft['destination'],'complement':''} client.call('/operator/quotes/'+qid+'/approve',{'items':items},operator=True,expected=409) assert not client.call('/quotes/'+qid)['auto_approved'] @@ -331,7 +335,7 @@ def run(): if state=='tra': # The queue takes approved final files only. client.call('/operator/orders/'+oid+'/move',{'state':'tra','version':version},operator=True,expected=409) - files=[{'item_index':i,'upload_id':upload_bytes(client,final_png_bytes(str(i)),name=f'LOCAL-FINAL-{i}.png',order_id=oid)} for i in range(4)] + files=[{'item_index':i,'upload_id':upload_bytes(client,final_png_bytes(str(i)),name=f'LOCAL-FINAL-{i}.png',order_id=oid)} for i in range(len(items))] result=client.call('/operator/orders/'+oid+'/final-files',{'version':version,'files':files,'note':'Local test manual final-file approval'},operator=True) version=result['version'] body={'state':state,'version':version,'reason':'Local test correction' if state=='cor' else ''} diff --git a/tests/test_one_machine.py b/tests/test_one_machine.py new file mode 100644 index 0000000..4c00401 --- /dev/null +++ b/tests/test_one_machine.py @@ -0,0 +1,29 @@ +"""One order, one machine (Marcus, 2026-11-26): UV and textile never share an +order; basic and premium textile may. + +Run from the repository root: python3 -m unittest tests.test_one_machine -v. +""" +import unittest + +from app.core.models import ONE_MACHINE, Item, check_one_machine +from tests.test_sheet_trim import sheet_item + + +def items(*modes): + return [Item.model_validate(sheet_item(mode=mode)) for mode in modes] + + +class OneMachineTests(unittest.TestCase): + def test_uv_and_textile_never_share_an_order(self): + for modes in (('file', 'uvfile'), ('premium', 'uvfile'), ('uvfile', 'file', 'file')): + with self.assertRaises(ValueError) as caught: + check_one_machine(items(*modes)) + self.assertEqual(str(caught.exception), ONE_MACHINE) + + def test_one_line_passes(self): + check_one_machine(items('file', 'premium', 'file')) + check_one_machine(items('uvfile', 'uvfile')) + + +if __name__ == '__main__': + unittest.main() diff --git a/web/index.html b/web/index.html index 105b43f..0768b88 100644 --- a/web/index.html +++ b/web/index.html @@ -974,6 +974,13 @@ h2 em{font-style:normal;color:var(--laranja)}
+