fix: Tiny's pickup is "Retirar pessoalmente", even with "Retirar na loja" there
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 4m9s
Build and deploy / Secret scan and release gate (push) Successful in 12s
Build and deploy / Publish images (push) Successful in 1m42s
All checks were successful
Build and deploy / Validate source (push) Successful in 14s
Build and deploy / Integration suite on a real stack (push) Successful in 4m9s
Build and deploy / Secret scan and release gate (push) Successful in 12s
Build and deploy / Publish images (push) Successful in 1m42s
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user