feat: montador Interno and Venda, Tiny customers, brand per stamp (front 7a.3, Marcus 10/11)
Interno: the Expedição assembles the marketplace's own sales on the fixed internal customer Gestão fills in once; no Tiny order, no paid e-mail, marked interno, it stays in house. Venda: a Vendedor or Gestão picks the customer from the Tiny base and the order goes to Tiny like an approved quote, faturado (Boleto from TINY_RECEIPT_BOLETO when set), pickup or 'junto com o pedido de roupa nº X'. Números counts both at table price, apart from cash (and the average ticket over cash orders only). Each stamp can carry a brand and a public flag for the future catalogue. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
"""The montador: stamp sizes, and the invoiced order a sheet becomes.
|
||||
"""The montador: stamp sizes, brand per stamp, and the Interno and Venda
|
||||
orders a sheet becomes (fronts 7a to 7a.3).
|
||||
|
||||
Run against the local stack: python -m tests.stamps_test
|
||||
"""
|
||||
@@ -14,6 +15,7 @@ from tests.smoke_test import Client
|
||||
|
||||
PASSWORD = 'senha-de-teste-123'
|
||||
PNG = (Path(__file__).resolve().parent / 'fixtures' / 'final-300.png').read_bytes()
|
||||
INTERNAL_MISSING = 'Peça à Gestão para completar o cliente interno.'
|
||||
|
||||
|
||||
def signed_in(email, password=PASSWORD):
|
||||
@@ -55,6 +57,10 @@ def montador_item(uid, mode='avulsa'):
|
||||
'quality_status': 'ok', 'quality_acknowledged': False, 'residue_accepted': 0}
|
||||
|
||||
|
||||
def price_table(stats):
|
||||
return {row['method']: row for row in stats['price_table']}
|
||||
|
||||
|
||||
def run():
|
||||
tag = secrets.token_hex(3)
|
||||
su = Client()
|
||||
@@ -62,27 +68,37 @@ def run():
|
||||
assert su.call('/operator/me', operator=True)['role'] == 'superadmin'
|
||||
with db.connect() as c:
|
||||
original = c.execute('SELECT letter,width_cm FROM dtf_local.stamp_sizes ORDER BY width_cm, letter').fetchall()
|
||||
emails = {role: f'{role}-{tag}@example.test' for role in ('expedicao', 'designer', 'gestao')}
|
||||
internal = c.execute('SELECT name,cnpj,zap,mail FROM dtf_local.internal_customer').fetchone()
|
||||
# The seed state: only the name, so Interno must be refused until
|
||||
# Gestão completes the other fields.
|
||||
c.execute("UPDATE dtf_local.internal_customer SET name='Nexstar · Marketplace',"
|
||||
"cnpj='',zap='',mail=''")
|
||||
emails = {role: f'{role}-{tag}@example.test' for role in ('expedicao', 'vendedor', 'designer', 'gestao')}
|
||||
table = [(row['letter'], float(row['width_cm'])) for row in original]
|
||||
customer = {'name': 'Cliente Montador', 'cnpj': '11222333000181', 'zap': '16999999999',
|
||||
'mail': f'montador-{tag}@example.test'}
|
||||
identity = operator_identity(emails['expedicao'])
|
||||
internal_customer = {'name': 'Nexstar · Marketplace', 'cnpj': '11222333000181',
|
||||
'zap': '1633334444', 'mail': f'interno-{tag}@example.test'}
|
||||
venda_customer = {'name': 'Maria Souza', 'cnpj': '12345678909',
|
||||
'zap': '16988887777', 'mail': f'venda-{tag}@example.test'}
|
||||
identities = [operator_identity(emails['expedicao']), operator_identity(emails['vendedor'])]
|
||||
made_orders, made_quotes = [], []
|
||||
# A code of its own, so a brand someone saved in Estampas/ is never touched.
|
||||
stamp_code = 'T' + tag
|
||||
try:
|
||||
for role, email in emails.items():
|
||||
su.call('/operator/users', {'name': role.title(), 'email': email, 'role': role,
|
||||
'password': PASSWORD}, operator=True)
|
||||
# The new profile creates through the users API and reads the table.
|
||||
shipping = signed_in(emails['expedicao'])
|
||||
seller = signed_in(emails['vendedor'])
|
||||
manager = signed_in(emails['gestao'])
|
||||
designer = signed_in(emails['designer'])
|
||||
me = shipping.call('/operator/me')
|
||||
assert me['role'] == 'expedicao' and me['can'] == ['assemble', 'view'], me
|
||||
read = shipping.call('/operator/stamp-sizes')['sizes']
|
||||
assert [(row['letter'], float(row['width_cm'])) for row in read] == table, read
|
||||
# The designer does not assemble: no reading the table.
|
||||
designer = signed_in(emails['designer'])
|
||||
designer.call('/operator/stamp-sizes', expected=403)
|
||||
# Gestão replaces the whole table in one go and reads it back, by width.
|
||||
manager = signed_in(emails['gestao'])
|
||||
manager.call('/operator/stamp-sizes', {'sizes': [{'letter': 'D', 'width_cm': 30},
|
||||
{'letter': 'A', 'width_cm': 20},
|
||||
{'letter': 'B', 'width_cm': 24.5}]})
|
||||
@@ -102,35 +118,95 @@ def run():
|
||||
read = manager.call('/operator/stamp-sizes')['sizes']
|
||||
assert [(row['letter'], float(row['width_cm'])) for row in read] == [('A', 20), ('B', 24.5), ('D', 30)], read
|
||||
|
||||
# The montador's order: the stamp upload, then the invoiced card in rec.
|
||||
# The brand per stamp: read by whoever assembles, saved by Gestão.
|
||||
default = shipping.call('/operator/stamps/' + stamp_code)
|
||||
assert default == {'code': stamp_code, 'brand': '', 'public': False}, default
|
||||
manager.call('/operator/stamps/' + stamp_code, {'brand': 'Dropstar', 'public': True})
|
||||
saved = shipping.call('/operator/stamps/' + stamp_code)
|
||||
assert saved == {'code': stamp_code, 'brand': 'Dropstar', 'public': True}, saved
|
||||
designer.call('/operator/stamps/' + stamp_code, {'brand': 'X', 'public': False}, expected=403)
|
||||
shipping.call('/operator/stamps/' + stamp_code, {'brand': 'X', 'public': False}, expected=403)
|
||||
|
||||
# The fake Tiny answers the Venda customer search with two contacts.
|
||||
contacts = shipping.call('/operator/tiny/contacts?q=Nexstar')
|
||||
assert len(contacts) == 2, contacts
|
||||
assert set(contacts[0]) == {'id', 'name', 'document', 'email', 'phone'}, contacts[0]
|
||||
assert contacts[0]['document'] == '11.222.333/0001-81', contacts[0]
|
||||
|
||||
# Interno is refused while Gestão has not completed the customer.
|
||||
stamp = upload_stamp(shipping)
|
||||
request_key = uuid4()
|
||||
body = {'request_key': str(request_key), 'customer': customer,
|
||||
'items': [montador_item(stamp)]}
|
||||
order = shipping.call('/operator/montador/orders', body)
|
||||
made_orders.append(UUID(order['id']))
|
||||
made_quotes.append(UUID(order['quote_id']))
|
||||
assert order['state'] == 'rec' and order['origin'] == 'dropflow', order
|
||||
payment = order['payment']
|
||||
assert (payment['provider'], payment['method'], payment['status']) == ('manual', 'faturado', 'paid'), payment
|
||||
assert payment['total_cents'] == order['snapshot']['total_cents'], payment
|
||||
interno = {'kind': 'interno', 'items': [montador_item(stamp)]}
|
||||
refused = shipping.call('/operator/montador/orders', {'request_key': str(uuid4()), **interno},
|
||||
expected=409)
|
||||
assert refused['detail'] == INTERNAL_MISSING, refused
|
||||
manager.call('/operator/internal-customer', internal_customer)
|
||||
completed = shipping.call('/operator/internal-customer')
|
||||
assert (completed['name'], completed['cnpj'], completed['zap'], completed['mail']) == (
|
||||
'Nexstar · Marketplace', '11222333000181', '1633334444', internal_customer['mail']), completed
|
||||
|
||||
before_stats = manager.call('/operator/stats?days=30')
|
||||
before = price_table(before_stats)
|
||||
# Interno: the fixed customer, origin dropflow, no Tiny, no paid e-mail.
|
||||
order_interno = shipping.call('/operator/montador/orders', {'request_key': str(uuid4()), **interno})
|
||||
made_orders.append(UUID(order_interno['id']))
|
||||
made_quotes.append(UUID(order_interno['quote_id']))
|
||||
assert order_interno['state'] == 'rec' and order_interno['origin'] == 'dropflow', order_interno
|
||||
assert order_interno['snapshot']['kind'] == 'interno', order_interno['snapshot'].get('kind')
|
||||
assert order_interno['snapshot']['customer']['cnpj'] == '11222333000181', order_interno['snapshot']
|
||||
payment = order_interno['payment']
|
||||
assert (payment['provider'], payment['method'], payment['status']) == ('manual', 'interno', 'paid'), payment
|
||||
with db.connect() as c:
|
||||
assert c.execute('SELECT 1 FROM dtf_local.print_files WHERE order_id=%s',
|
||||
(UUID(order['id']),)).fetchone()
|
||||
(UUID(order_interno['id']),)).fetchone()
|
||||
assert not c.execute('SELECT 1 FROM dtf_local.outbox WHERE event_key=%s',
|
||||
(f"{order['id']}:paid:tiny",)).fetchone()
|
||||
(f"{order_interno['id']}:paid:tiny",)).fetchone()
|
||||
assert not c.execute('SELECT 1 FROM dtf_local.mail_queue WHERE to_addr=%s',
|
||||
(internal_customer['mail'],)).fetchone()
|
||||
|
||||
# Venda: a Tiny customer, origin atendimento, invoiced and sent to Tiny.
|
||||
venda_stamp = upload_stamp(seller)
|
||||
venda = {'kind': 'venda', 'customer': venda_customer, 'with_order': 4321,
|
||||
'items': [montador_item(venda_stamp)]}
|
||||
venda_body = {'request_key': str(uuid4()), **venda}
|
||||
order_venda = seller.call('/operator/montador/orders', venda_body)
|
||||
made_orders.append(UUID(order_venda['id']))
|
||||
made_quotes.append(UUID(order_venda['quote_id']))
|
||||
assert order_venda['state'] == 'rec' and order_venda['origin'] == 'atendimento', order_venda
|
||||
assert order_venda['snapshot']['with_order'] == 4321, order_venda['snapshot'].get('with_order')
|
||||
payment = order_venda['payment']
|
||||
assert (payment['provider'], payment['method'], payment['status']) == ('manual', 'faturado', 'paid'), payment
|
||||
with db.connect() as c:
|
||||
assert c.execute('SELECT 1 FROM dtf_local.outbox WHERE event_key=%s AND provider=%s',
|
||||
(f"{order_venda['id']}:paid:tiny", 'tiny')).fetchone()
|
||||
assert not c.execute('SELECT 1 FROM dtf_local.mail_queue WHERE to_addr=%s',
|
||||
(venda_customer['mail'],)).fetchone()
|
||||
|
||||
# Números: both are counted apart from the money received.
|
||||
after_stats = manager.call('/operator/stats?days=30')
|
||||
after = price_table(after_stats)
|
||||
for method, order in (('interno', order_interno), ('faturado', order_venda)):
|
||||
assert after[method]['orders'] == before[method]['orders'] + 1, (method, before[method], after[method])
|
||||
assert after[method]['cents'] == before[method]['cents'] + order['snapshot']['total_cents'], (method, before[method], after[method])
|
||||
assert after[method]['metres'] > before[method]['metres'], (method, before[method], after[method])
|
||||
assert after_stats['cents'] == before_stats['cents'], (before_stats['cents'], after_stats['cents'])
|
||||
|
||||
# The same montagem cannot become a second order.
|
||||
refused = shipping.call('/operator/montador/orders', body, expected=409)
|
||||
assert refused['detail'] == f"Esta montagem já virou o pedido #{order['number']}.", refused
|
||||
# A designer does not use the montador, and only loose art becomes one.
|
||||
refused = seller.call('/operator/montador/orders', venda_body, expected=409)
|
||||
assert refused['detail'] == f"Esta montagem já virou o pedido #{order_venda['number']}.", refused
|
||||
# Each profile makes only its own kind, and only loose art becomes one.
|
||||
seller.call('/operator/montador/orders', {'request_key': str(uuid4()), **interno}, expected=403)
|
||||
shipping.call('/operator/montador/orders', {'request_key': str(uuid4()), **venda}, expected=403)
|
||||
designer.call('/operator/montador/uploads', {'name': 'ESTAMPA.png', 'size': 1}, expected=403)
|
||||
designer.call('/operator/montador/orders', body, expected=403)
|
||||
shipping.call('/operator/montador/orders', {'request_key': str(uuid4()), 'customer': customer,
|
||||
designer.call('/operator/montador/orders', {'request_key': str(uuid4()), **venda}, expected=403)
|
||||
shipping.call('/operator/montador/orders', {'request_key': str(uuid4()), 'kind': 'interno',
|
||||
'items': [montador_item(stamp, 'file')]}, expected=422)
|
||||
print('PASS: Expedição reads the sizes, uploads a stamp and gets the invoiced montador card; '
|
||||
'Gestão edits the table; invalid rows, profiles and modes are refused')
|
||||
print('PASS: Expedição makes Interno and Vendedor makes Venda; the internal customer, the Tiny '
|
||||
'contacts, the stamp brand and the table price in Números work; invalid profiles and modes are refused')
|
||||
finally:
|
||||
with db.connect() as c:
|
||||
if made_orders:
|
||||
c.execute("DELETE FROM dtf_local.outbox WHERE payload->>'order_id' = ANY(%s::text[])",
|
||||
([str(oid) for oid in made_orders],))
|
||||
for oid in made_orders:
|
||||
c.execute('DELETE FROM dtf_local.print_files WHERE order_id=%s', (oid,))
|
||||
c.execute('DELETE FROM dtf_local.order_files WHERE order_id=%s', (oid,))
|
||||
@@ -139,8 +215,13 @@ def run():
|
||||
c.execute('DELETE FROM dtf_local.orders WHERE id=%s', (oid,))
|
||||
if made_quotes:
|
||||
c.execute('DELETE FROM dtf_local.quotes WHERE id=ANY(%s)', (made_quotes,))
|
||||
c.execute('DELETE FROM dtf_local.mail_queue WHERE to_addr=%s', (customer['mail'],))
|
||||
c.execute('DELETE FROM dtf_local.uploads WHERE owner=%s', (identity,))
|
||||
c.execute('DELETE FROM dtf_local.mail_queue WHERE to_addr IN (%s,%s)',
|
||||
(internal_customer['mail'], venda_customer['mail']))
|
||||
for identity in identities:
|
||||
c.execute('DELETE FROM dtf_local.uploads WHERE owner=%s', (identity,))
|
||||
c.execute('DELETE FROM dtf_local.stamps WHERE code=%s', (stamp_code,))
|
||||
c.execute('UPDATE dtf_local.internal_customer SET name=%s,cnpj=%s,zap=%s,mail=%s',
|
||||
(internal['name'], internal['cnpj'], internal['zap'], internal['mail']))
|
||||
c.execute('DELETE FROM dtf_local.stamp_sizes')
|
||||
c.cursor().executemany('INSERT INTO dtf_local.stamp_sizes(letter,width_cm) VALUES(%s,%s)', table)
|
||||
c.execute('DELETE FROM dtf_local.operators WHERE email LIKE %s', (f'%-{tag}@example.test',))
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
"""Who moves which card on the Kanban: Dropstar's flow of 2026-10-23."""
|
||||
import os
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from app import payments
|
||||
from app import payments, tiny
|
||||
from app.core import auth
|
||||
from app.core.auth import CAPABILITIES, ROLES, may_move, may_reorder
|
||||
from app.runtime import BACK, STATES, TRANSITIONS
|
||||
@@ -78,14 +79,31 @@ class CanAnyTest(unittest.TestCase):
|
||||
route(None)
|
||||
|
||||
|
||||
class InvoicedOrderTest(unittest.TestCase):
|
||||
def test_an_invoiced_montador_order_is_held_out_of_tiny(self):
|
||||
class MontadorPaymentTest(unittest.TestCase):
|
||||
def test_a_faturado_order_goes_to_tiny_and_an_internal_one_does_not(self):
|
||||
self.assertEqual(payments.INVOICED_METHOD, 'faturado')
|
||||
# It is not one of the Cotações "registrar" methods.
|
||||
self.assertEqual(payments.INTERNAL_METHOD, 'interno')
|
||||
# Neither is one of the Cotações "registrar" methods.
|
||||
self.assertNotIn(payments.INVOICED_METHOD, payments.OUTSIDE_METHODS)
|
||||
self.assertFalse(payments.in_tiny({'payment': {'provider': 'manual', 'method': 'faturado'}}))
|
||||
self.assertNotIn(payments.INTERNAL_METHOD, payments.OUTSIDE_METHODS)
|
||||
self.assertTrue(payments.in_tiny({'payment': {'provider': 'manual', 'method': 'faturado'}}))
|
||||
self.assertFalse(payments.in_tiny({'payment': {'provider': 'manual', 'method': 'interno'}}))
|
||||
self.assertTrue(payments.in_tiny({'payment': {'provider': 'manual', 'method': 'pix'}}))
|
||||
|
||||
|
||||
class InternalNoteTest(unittest.TestCase):
|
||||
payload = {'order_id': 'b6f1c0de-0000-4000-8000-000000000001', 'number': 42,
|
||||
'origin': 'atendimento', 'payment': {'method': 'faturado', 'outside': True},
|
||||
'order': {'with_order': 4321}}
|
||||
|
||||
def test_an_invoiced_order_says_how_it_is_received(self):
|
||||
with mock.patch.dict(os.environ, {'TINY_RECEIPT_BOLETO': ''}):
|
||||
note = tiny.internal_note(self.payload)
|
||||
self.assertIn('faturado: forma de recebimento a definir', note)
|
||||
self.assertIn('junto com o pedido de roupa nº 4321', note)
|
||||
with mock.patch.dict(os.environ, {'TINY_RECEIPT_BOLETO': '123456'}):
|
||||
self.assertIn('faturado (Boleto)', tiny.internal_note(self.payload))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user