feat: UV goes to Tiny as whole metres of DTFIMP.UV.1MT, then DTFIMP.UV.010CM
All checks were successful
Build and deploy / Validate source (push) Successful in 1m22s
Build and deploy / Integration suite on a real stack (push) Successful in 3m12s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 58s

The client registered UV as a metre SKU and a 10 cm SKU. With
TINY_SKU_METRO_<MODE> beside TINY_SKU10_<MODE>, 2,30 m goes as 2 × the
metre SKU and 3 × the 10 cm one, at the price the customer paid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-07 15:00:00 -03:00
parent 44cb6ccc16
commit 3db528a373
6 changed files with 66 additions and 8 deletions

View File

@@ -49,10 +49,12 @@ PRODUCT_SETTINGS = {'file': 'TINY_PRODUCT_TEXTIL_FOLHA', 'avulsa': 'TINY_PRODUCT
# the mode's product id.
SKU_SETTINGS = {'file': 'TINY_SKU_TEXTIL_FOLHA', 'avulsa': 'TINY_SKU_TEXTIL_AVULSA',
'uvfile': 'TINY_SKU_UV_FOLHA', 'uv': 'TINY_SKU_UV_AVULSA'}
# Or a single SKU per 10 cm, as the client sells UV ("DTFIMP.UV.010CM"):
# 2,30 m is 23 of it.
# Or a SKU per 10 cm ("DTFIMP.UV.010CM"), alone (2,30 m is 23 of it) or after
# a metre SKU ("DTFIMP.UV.1MT"): 2,30 m is 2 metres and 3 of the 10 cm.
STEP_SETTINGS = {'file': 'TINY_SKU10_TEXTIL_FOLHA', 'avulsa': 'TINY_SKU10_TEXTIL_AVULSA',
'uvfile': 'TINY_SKU10_UV_FOLHA', 'uv': 'TINY_SKU10_UV_AVULSA'}
METRE_SETTINGS = {'file': 'TINY_SKU_METRO_TEXTIL_FOLHA', 'avulsa': 'TINY_SKU_METRO_TEXTIL_AVULSA',
'uvfile': 'TINY_SKU_METRO_UV_FOLHA', 'uv': 'TINY_SKU_METRO_UV_AVULSA'}
PRODUCTS = {'file': 'DTF Têxtil 57 cm · folha montada',
'avulsa': 'DTF Têxtil 57 cm · artes avulsas',
'uvfile': 'DTF UV 28,5 cm · folha montada',
@@ -116,10 +118,15 @@ def step_sku(mode):
return os.environ.get(STEP_SETTINGS[mode], '').strip()
def metre_sku(mode):
"""The metre SKU paired with a 10 cm SKU, or '' when the 10 cm one goes alone."""
return os.environ.get(METRE_SETTINGS[mode], '').strip() if step_sku(mode) else ''
def mode_codes(mode):
"""Every SKU code a mode sold by SKU uses, or [] for a mode sold by product id."""
if step_sku(mode):
return [step_sku(mode)]
return [code for code in (metre_sku(mode), step_sku(mode)) if code]
return sku_codes(sku_prefix(mode)) if sku_prefix(mode) else []
@@ -137,10 +144,23 @@ def tenths(item):
return int(steps), int(billed * int(item['unit_cents']))
def step_lines(item, code):
"""(code, quantity, cents each) for a single 10 cm SKU, adding up to the
item's total; a rest that does not divide goes on one line of its own."""
def step_lines(item, code, metre=''):
"""(code, quantity, cents each) for a 10 cm SKU, after whole metres of the
metre SKU when there is one, adding up to the item's total; a rest that
does not divide goes on one line of its own."""
steps, total = tenths(item)
lines = []
if metre and steps >= 10:
metres, steps = divmod(steps, 10)
unit = int(item['unit_cents'])
lines.append((metre, metres, unit))
total -= metres * unit
if not steps:
return lines
return lines + split_steps(code, steps, total)
def split_steps(code, steps, total):
each, rest = divmod(total, steps)
if not rest:
return [(code, steps, each)]
@@ -354,7 +374,7 @@ def order_payload(payload, contact_id, today=None, product_id=None):
if step or prefix:
if product_id is None:
raise TinyError(f"{SKU_SETTINGS[item['mode']]} needs the SKUs looked up in Tiny")
lines = step_lines(item, step) if step else sku_lines(item, prefix)
lines = step_lines(item, step, metre_sku(item['mode'])) if step else sku_lines(item, prefix)
for index, (code, quantity, cents) in enumerate(lines):
line = {'produto': {'id': product_id(code)}, 'quantidade': quantity, 'valorUnitario': money(cents)}
if index == 0:

View File

@@ -71,7 +71,9 @@ def conferir(orders, out):
if step:
result = tiny.configured_skus(orders, mode)
ok &= result == 'ok'
out(f'{tiny.STEP_SETTINGS[mode]} ({tiny.PRODUCTS[mode]}): {result} ({step} a cada 10 cm)')
metre = tiny.metre_sku(mode)
out(f'{tiny.STEP_SETTINGS[mode]} ({tiny.PRODUCTS[mode]}): {result} '
f'({metre + " por metro e " if metre else ""}{step} a cada 10 cm)')
continue
if prefix:
result = tiny.configured_skus(orders, mode)

View File

@@ -66,6 +66,10 @@ x-app: &app
TINY_SKU10_TEXTIL_AVULSA: ${TINY_SKU10_TEXTIL_AVULSA:-}
TINY_SKU10_UV_FOLHA: ${TINY_SKU10_UV_FOLHA:-}
TINY_SKU10_UV_AVULSA: ${TINY_SKU10_UV_AVULSA:-}
TINY_SKU_METRO_TEXTIL_FOLHA: ${TINY_SKU_METRO_TEXTIL_FOLHA:-}
TINY_SKU_METRO_TEXTIL_AVULSA: ${TINY_SKU_METRO_TEXTIL_AVULSA:-}
TINY_SKU_METRO_UV_FOLHA: ${TINY_SKU_METRO_UV_FOLHA:-}
TINY_SKU_METRO_UV_AVULSA: ${TINY_SKU_METRO_UV_AVULSA:-}
TINY_ECOMMERCE_ID: ${TINY_ECOMMERCE_ID:-}
WHATSAPP_ADAPTER: fake
STORAGE_ADAPTER: s3-local

View File

@@ -80,6 +80,10 @@ x-app-environment: &app-environment
TINY_SKU10_TEXTIL_AVULSA: ${TINY_SKU10_TEXTIL_AVULSA:-}
TINY_SKU10_UV_FOLHA: ${TINY_SKU10_UV_FOLHA:-}
TINY_SKU10_UV_AVULSA: ${TINY_SKU10_UV_AVULSA:-}
TINY_SKU_METRO_TEXTIL_FOLHA: ${TINY_SKU_METRO_TEXTIL_FOLHA:-}
TINY_SKU_METRO_TEXTIL_AVULSA: ${TINY_SKU_METRO_TEXTIL_AVULSA:-}
TINY_SKU_METRO_UV_FOLHA: ${TINY_SKU_METRO_UV_FOLHA:-}
TINY_SKU_METRO_UV_AVULSA: ${TINY_SKU_METRO_UV_AVULSA:-}
# The client's "retirar pessoalmente" forma de envio id, on pickup orders.
TINY_FORMA_ENVIO_RETIRADA: ${TINY_FORMA_ENVIO_RETIRADA:-}
# Sets "Aprovada" on paid orders and "Pronto para envio" on finished pickup

View File

@@ -316,6 +316,8 @@ TINY_SKU_UV_FOLHA=
TINY_SKU_UV_AVULSA=
TINY_SKU10_UV_FOLHA=DTFIMP.UV.010CM # or one SKU per 10 cm: 2,30 m = 23 of it (the client's UV)
TINY_SKU10_UV_AVULSA=DTFIMP.UV.010CM
TINY_SKU_METRO_UV_FOLHA=DTFIMP.UV.1MT # with a 10 cm SKU: whole metres first (2,30 m = 2 × 1MT + 3 × 010CM)
TINY_SKU_METRO_UV_AVULSA=DTFIMP.UV.1MT
```
With the client ID and secret set, the Kanban header shows **Conectar Tiny**.

View File

@@ -336,6 +336,32 @@ class TinyStepSkuTests(FakeTinyCase):
self.assertIn('DTFIMP.UV.010CM', check(orders=self.tiny)['DTF UV 28,5 cm · folha montada'])
@mock.patch.dict(os.environ, {**PRODUCTS, 'TINY_SKU10_UV_FOLHA': 'DTFIMP.UV.010CM',
'TINY_SKU_METRO_UV_FOLHA': 'DTFIMP.UV.1MT'})
class TinyMetreAndStepSkuTests(FakeTinyCase):
"""UV as the client registered it: DTFIMP.UV.1MT per metre and DTFIMP.UV.010CM per 10 cm."""
def setUp(self):
super().setUp()
self.products['300'] = {'id': 300, 'sku': 'DTFIMP.UV.010CM', 'descricao': 'UV 10 cm', 'situacao': 'A'}
self.products['301'] = {'id': 301, 'sku': 'DTFIMP.UV.1MT', 'descricao': 'UV 1 metro', 'situacao': 'A'}
def test_whole_metres_then_ten_centimetre_steps(self):
self.tiny.deliver('k1', UV)
lines = [(i['produto']['id'], i['quantidade'], i['valorUnitario']) for i in self.orders[0]['itens']]
# 2,30 m at R$ 69,90: 2 × "1 metro" + 3 × "10 cm", R$ 160,77 in all.
self.assertEqual(lines, [(301, 2, 69.9), (300, 3, 6.99)])
self.assertAlmostEqual(sum(q * v for _, q, v in lines), 160.77)
def test_whole_metres_alone_and_the_check(self):
from app.tiny import check, step_lines
self.assertEqual(step_lines({'billed_metres': '2', 'unit_cents': 6990}, 'C', 'M'), [('M', 2, 6990)])
self.assertEqual(check(orders=self.tiny)['DTF UV 28,5 cm · folha montada'], 'ok')
del self.products['301']
self.tiny.skus.clear()
self.assertIn('DTFIMP.UV.1MT', check(orders=self.tiny)['DTF UV 28,5 cm · folha montada'])
@mock.patch.dict(os.environ, PRODUCTS)
class TinyProbeTests(FakeTinyCase):
"""The supervised console tool run against the fake Tiny."""