feat: Boleto with its bank account and Ajuste Fino by SKU in Tiny (Marcus, 12/11)
A faturado montador order's installments carry the bank account set in TINY_BOLETO_ACCOUNT as their meioPagamento (Tiny v3 parcelas[]), so Tiny does not pick another account. The Ajuste Fino line resolves the product from its code (TINY_SKU_TREATMENT, default DTFIMP.AJF.UN) unless a numeric TINY_PRODUCT_TREATMENT is set; the connection check verifies it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,6 +61,9 @@ class FakeTinyCase(unittest.TestCase):
|
||||
'formasFrete': [{'id': 801, 'nome': '.PACKAGE', 'codigo': '3'}]}}
|
||||
self.products = {value: {'id': int(value), 'sku': f'DTF-{value}', 'descricao': f'Produto {value}',
|
||||
'situacao': 'A', 'precos': {'preco': 14.9}} for value in PRODUCTS.values()}
|
||||
# Ajuste Fino, per art: the SKU Marcus registered (2026-11-12).
|
||||
self.products['106'] = {'id': 106, 'sku': 'DTFIMP.AJF.UN', 'descricao': 'Ajuste Fino',
|
||||
'situacao': 'A', 'precos': {'preco': 6.9}}
|
||||
|
||||
def handler(request):
|
||||
path = request.url.path.removeprefix('/public-api/v3')
|
||||
@@ -157,9 +160,11 @@ class TinyTests(FakeTinyCase):
|
||||
treatment = {'order': {**base, 'treatment': {'cents': 990, 'hours': 24},
|
||||
'total_cents': base['total_cents'] + 990},
|
||||
**{k: v for k, v in PAID.items() if k != 'order'}}
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '105'}):
|
||||
pedido = order_payload(treatment, 777, date(2026, 9, 24))
|
||||
self.assertIn({'produto': {'id': 105}, 'quantidade': 1, 'valorUnitario': 9.9,
|
||||
# Ajuste Fino is sold by the SKU Marcus registered, found in the
|
||||
# catalogue: the arts are its quantity and the band its unit price.
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '', 'TINY_SKU_TREATMENT': ''}):
|
||||
pedido = order_payload(treatment, 777, date(2026, 9, 24), product_id=self.tiny.product_id)
|
||||
self.assertIn({'produto': {'id': 106}, 'quantidade': 1, 'valorUnitario': 9.9,
|
||||
'infoAdicional': 'Ajuste Fino · 1 arte · +24 h'}, pedido['itens'])
|
||||
self.assertNotEqual(pedido['dataPrevista'], order_payload(plain, 777, date(2026, 9, 24))['dataPrevista'])
|
||||
# Per art: the quantity is the number of arts and the unit is the band price.
|
||||
@@ -167,10 +172,48 @@ class TinyTests(FakeTinyCase):
|
||||
'unit_cents': 690},
|
||||
'total_cents': base['total_cents'] + 2070},
|
||||
**{k: v for k, v in PAID.items() if k != 'order'}}
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '', 'TINY_SKU_TREATMENT': ''}):
|
||||
pedido = order_payload(per_art, 777, date(2026, 9, 24), product_id=self.tiny.product_id)
|
||||
self.assertIn({'produto': {'id': 106}, 'quantidade': 3, 'valorUnitario': 6.9,
|
||||
'infoAdicional': 'Ajuste Fino · 3 artes · +24 h'}, pedido['itens'])
|
||||
# The numeric id, when the client gives one, still wins.
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '105'}):
|
||||
pedido = order_payload(per_art, 777, date(2026, 9, 24))
|
||||
self.assertIn({'produto': {'id': 105}, 'quantidade': 3, 'valorUnitario': 6.9,
|
||||
'infoAdicional': 'Ajuste Fino · 3 artes · +24 h'}, pedido['itens'])
|
||||
# Without the numeric id, the catalogue lookup is required before sending.
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '', 'TINY_SKU_TREATMENT': ''}):
|
||||
with self.assertRaisesRegex(TinyError, 'TINY_SKU_TREATMENT'):
|
||||
order_payload(treatment, 777, date(2026, 9, 24))
|
||||
|
||||
def test_faturado_boleto_carries_its_bank_account_on_the_installment(self):
|
||||
boleto = {'TINY_RECEIPT_BOLETO': '919478947'}
|
||||
with mock.patch.dict(os.environ, {**boleto, 'TINY_BOLETO_ACCOUNT': '977344551'}), \
|
||||
mock.patch.dict(tiny_module.RECEIPT_METHODS, {'faturado': 919478947}):
|
||||
pedido = order_payload({**PAID, 'payment': {'method': 'faturado'}}, 777, date(2026, 9, 24))
|
||||
self.assertEqual(pedido['pagamento']['formaRecebimento'], {'id': 919478947})
|
||||
# Every installment names the account: Tiny must not choose its preferred one.
|
||||
self.assertEqual(pedido['pagamento']['parcelas'], [{
|
||||
'dias': 0, 'data': '2026-09-24', 'valor': 84.72,
|
||||
'formaRecebimento': {'id': 919478947}, 'meioPagamento': {'id': 977344551}}])
|
||||
self.assertIn('faturado (Boleto)', pedido['observacoesInternas'])
|
||||
# Without the account setting, no account is sent at all.
|
||||
with mock.patch.dict(os.environ, {**boleto, 'TINY_BOLETO_ACCOUNT': ''}), \
|
||||
mock.patch.dict(tiny_module.RECEIPT_METHODS, {'faturado': 919478947}):
|
||||
pedido = order_payload({**PAID, 'payment': {'method': 'faturado'}}, 777, date(2026, 9, 24))
|
||||
self.assertNotIn('meioPagamento', pedido['pagamento']['parcelas'][0])
|
||||
# A pix order never gets the boleto account.
|
||||
with mock.patch.dict(os.environ, {'TINY_BOLETO_ACCOUNT': '977344551'}):
|
||||
pedido = order_payload({**PAID, 'payment': {'method': 'pix'}}, 777, date(2026, 9, 24))
|
||||
self.assertNotIn('meioPagamento', pedido['pagamento']['parcelas'][0])
|
||||
|
||||
def test_the_check_lists_ajuste_fino_by_its_sku(self):
|
||||
from app.tiny import check
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '', 'TINY_SKU_TREATMENT': ''}):
|
||||
self.assertEqual(check(orders=self.tiny)['Ajuste Fino'], 'ok')
|
||||
self.products['106']['situacao'] = 'I'
|
||||
self.tiny.skus.clear()
|
||||
self.assertIn('DTFIMP.AJF.UN', check(orders=self.tiny)['Ajuste Fino'])
|
||||
|
||||
def test_second_delivery_finds_the_first_order(self):
|
||||
first = self.tiny.deliver('k1', PAID)
|
||||
@@ -231,7 +274,7 @@ class TinyTests(FakeTinyCase):
|
||||
from app.tiny import check
|
||||
results = check(auth=FakeAuth(), transport=httpx.MockTransport(self.handler))
|
||||
self.assertEqual(set(results.values()), {'ok'})
|
||||
self.assertEqual(len(results), 8)
|
||||
self.assertEqual(len(results), 9)
|
||||
self.assertTrue(all(method == 'GET' for method, _ in self.calls))
|
||||
self.products['103']['situacao'] = 'I'
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_UV_AVULSA': ''}):
|
||||
@@ -602,6 +645,7 @@ class TinyProbeTests(FakeTinyCase):
|
||||
code, text = self.probe('conferir')
|
||||
self.assertEqual(code, 0)
|
||||
self.assertIn('TINY_PRODUCT_UV_AVULSA (DTF UV 27 cm · artes avulsas): ok DTF-104', text)
|
||||
self.assertIn('TINY_SKU_TREATMENT (Ajuste Fino): ok DTFIMP.AJF.UN', text)
|
||||
self.assertIn('TINY_FORMA_ENVIO_RETIRADA (retirada): ok Retirar pessoalmente', text)
|
||||
code, text = self.probe('formas-envio')
|
||||
self.assertIn('77\t6\tRetirar pessoalmente', text)
|
||||
@@ -815,14 +859,14 @@ class DefaultSkuTests(unittest.TestCase):
|
||||
|
||||
|
||||
class TreatmentSettingTests(unittest.TestCase):
|
||||
"""A paid treatment needs its own Tiny product, asked with the rest."""
|
||||
"""Ajuste Fino is sold by its SKU, so no product id is required any more."""
|
||||
|
||||
def test_the_treatment_product_is_required_only_when_it_is_paid(self):
|
||||
def test_the_treatment_id_is_never_required(self):
|
||||
from app.tiny import required_settings
|
||||
with mock.patch.dict(os.environ, {'TREATMENT_CENTS': '0'}):
|
||||
with mock.patch.dict(os.environ, {'TINY_PRODUCT_TREATMENT': '', 'TINY_SKU_TREATMENT': ''}):
|
||||
self.assertNotIn('TINY_PRODUCT_TREATMENT', required_settings())
|
||||
with mock.patch.dict(os.environ, {'TINY_SKU_TREATMENT': 'DTFIMP.AJF.LOTE'}):
|
||||
self.assertNotIn('TINY_PRODUCT_TREATMENT', required_settings())
|
||||
with mock.patch.dict(os.environ, {'TREATMENT_CENTS': '5000'}):
|
||||
self.assertIn('TINY_PRODUCT_TREATMENT', required_settings())
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
Reference in New Issue
Block a user