From f8d76ed27d542c409402c07ec30509a036fe40b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cau=C3=AA=20Faleiros?= Date: Wed, 14 Oct 2026 13:25:21 -0300 Subject: [PATCH] fix: Tiny's pickup is "Retirar pessoalmente", even with "Retirar na loja" there Dropstar's Tiny has two formas de envio named like "retirar": "Retirar pessoalmente", the one its team uses, and an unused "Retirar na loja", so the lookup by name asked for a setting. The exact name now decides; two other "retirar" methods still ask. Co-Authored-By: Claude Opus 5.5 --- app/tiny.py | 8 +++++++- tests/test_tiny.py | 8 ++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/tiny.py b/app/tiny.py index 9c85729..818a954 100644 --- a/app/tiny.py +++ b/app/tiny.py @@ -84,6 +84,7 @@ STATUS_UPDATES_SETTING = 'TINY_STATUS_UPDATES' # only overrides that. PICKUP_SETTING = 'TINY_FORMA_ENVIO_RETIRADA' PICKUP_NAME = 'retir' +PICKUP_EXACT = 'retirar pessoalmente' STATE_MINUTES = 10 # Renewal runs about every four hours against a one-day refresh token, so # less than this left means renewals have been failing for hours. @@ -454,9 +455,14 @@ def configured_skus(orders, mode): def find_pickup(orders): - """The one forma de envio named like "retirar", or why there is not one.""" + """The forma de envio named "Retirar pessoalmente" (Dropstar's), else the one + named like "retirar", or why there is not one.""" found = orders.request('GET', '/formas-envio', params={'nome': PICKUP_NAME, 'limit': 100}).get('itens') or [] named = [f for f in found if PICKUP_NAME in str(f.get('nome', '')).lower()] + # The account also has "Retirar na loja", unused: the exact name decides. + exact = [f for f in named if ' '.join(str(f.get('nome', '')).lower().split()) == PICKUP_EXACT] + if len(exact) == 1: + return exact[0], 'ok' if len(named) == 1: return named[0], 'ok' if not named: diff --git a/tests/test_tiny.py b/tests/test_tiny.py index d270a64..6c283d9 100644 --- a/tests/test_tiny.py +++ b/tests/test_tiny.py @@ -259,12 +259,16 @@ class TinyStatusTests(FakeTinyCase): self.assertNotIn('transportador', order_payload(PICKUP, 1)) def test_pickup_forma_de_envio_is_found_by_name(self): - from app.tiny import check + from app.tiny import check, find_pickup with mock.patch.dict(os.environ, {'TINY_FORMA_ENVIO_RETIRADA': ''}): self.tiny.deliver('k1', PICKUP) self.assertEqual(self.orders[0]['transportador'], {'formaEnvio': {'id': 77}}) self.assertEqual(check(orders=self.tiny)['forma de envio de retirada'], 'ok') - self.methods['79'] = {'id': 79, 'nome': 'Retirada na loja', 'tipo': '6'} + # Dropstar's account also has "Retirar na loja": the exact name wins. + self.methods['79'] = {'id': 79, 'nome': 'Retirar na loja', 'tipo': '6'} + self.assertEqual(check(orders=self.tiny)['forma de envio de retirada'], 'ok') + self.assertEqual(find_pickup(self.tiny)[0]['id'], 77) + self.methods['77']['nome'] = 'Retirar no balcão' self.assertIn('mais de uma', check(orders=self.tiny)['forma de envio de retirada']) del self.methods['77'], self.methods['79'] self.assertIn('nenhuma', check(orders=self.tiny)['forma de envio de retirada'])