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: