feat: a Jadlog quote counts one box per 60 m of film
All checks were successful
Build and deploy / Validate source (push) Successful in 1m20s
Build and deploy / Integration suite on a real stack (push) Successful in 3m11s
Build and deploy / Secret scan and release gate (push) Successful in 9s
Build and deploy / Publish images (push) Successful in 1m19s

The client corrected the box to 63 x 15.5 x 15.5 cm and said one box holds
about 60 m. JADLOG_METROS_POR_CAIXA quotes a longer order as several boxes,
each with its packaging weight and volume. UV ships in the same box.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Cauê Faleiros
2026-10-02 10:04:54 -03:00
parent 26c46ccc1d
commit 4b8b00443e
7 changed files with 51 additions and 9 deletions

View File

@@ -69,7 +69,8 @@ def freight_status():
'production_days': freight.production_days,
'box_cm': [str(side) for side in freight.box_cm] if freight.box_cm else None,
'cubage_kg_m3': str(freight.cubage_kg_m3) if freight.cubage_kg_m3 else None,
'cubed_kg': str(cubed) if cubed is not None else None}
'cubed_kg': str(cubed) if cubed is not None else None,
'metres_per_box': str(freight.metres_per_box) if freight.metres_per_box else None}
def backup_status(c):

View File

@@ -12,8 +12,11 @@ plus a weight per billed metre) and has no default: FREIGHT_ADAPTER=jadlog
refuses to start without it, so a guessed weight never prices a customer's
freight. The cubed weight is the box's volume times the contract's factor
(JADLOG_CAIXA_CM, JADLOG_CUBAGEM_KG_M3); set both or neither, and with neither
only the real weight is sent.
only the real weight is sent. A box holds JADLOG_METROS_POR_CAIXA metres of
film; a longer order ships in as many boxes as it needs, each with its own
packaging weight and volume.
"""
import math
import os
import re
from decimal import ROUND_HALF_UP, Decimal
@@ -117,20 +120,31 @@ class JadlogFreight:
self.cubage_kg_m3 = Decimal(factor.replace(',', '.')) if factor else None
if self.cubage_kg_m3 is not None and self.cubage_kg_m3 <= 0:
raise RuntimeError('JADLOG_CUBAGEM_KG_M3 must be positive')
per_box = (os.environ.get('JADLOG_METROS_POR_CAIXA') or '').strip()
self.metres_per_box = Decimal(per_box.replace(',', '.')) if per_box else None
if self.metres_per_box is not None and self.metres_per_box <= 0:
raise RuntimeError('JADLOG_METROS_POR_CAIXA must be positive')
def boxes(self, metres=None):
"""How many boxes the order fills; one when the capacity is not set."""
if metres is None or self.metres_per_box is None:
return 1
return max(1, math.ceil(Decimal(str(metres)) / self.metres_per_box))
def real_kg(self, metres):
return (self.base_kg + self.per_metre_kg * Decimal(str(metres))).quantize(GRAMS)
return (self.boxes(metres) * self.base_kg + self.per_metre_kg * Decimal(str(metres))).quantize(GRAMS)
def cubed_kg(self):
"""The box's volume in m³ times the contract's factor; None without a box."""
def cubed_kg(self, metres=None):
"""The boxes' volume in m³ times the contract's factor (one box without a
length); None without a box."""
if not self.box_cm:
return None
a, b, c = self.box_cm
return (a * b * c / Decimal(1_000_000) * self.cubage_kg_m3).quantize(GRAMS)
return (self.boxes(metres) * a * b * c / Decimal(1_000_000) * self.cubage_kg_m3).quantize(GRAMS)
def weight_kg(self, metres):
"""What Jadlog charges by: the larger of the real and the cubed weight."""
real, cubed = self.real_kg(metres), self.cubed_kg()
real, cubed = self.real_kg(metres), self.cubed_kg(metres)
return max(real, cubed) if cubed is not None else real
def quote(self, service, postal_code, metres=None, declared_cents=0):
@@ -148,5 +162,6 @@ class JadlogFreight:
days = result['days']
return {'provider': self.name, 'service': SERVICE, 'postal_code': postal_code,
'total_cents': result['total_cents'], 'weight_kg': str(weight), 'real_kg': str(real),
'boxes': self.boxes(metres),
'days': None if days is None else int(days) + self.production_days,
'description': 'Jadlog .PACKAGE'}

View File

@@ -45,6 +45,7 @@ x-app: &app
JADLOG_PESO_POR_METRO_KG: ${JADLOG_PESO_POR_METRO_KG:-}
JADLOG_CAIXA_CM: ${JADLOG_CAIXA_CM:-}
JADLOG_CUBAGEM_KG_M3: ${JADLOG_CUBAGEM_KG_M3:-}
JADLOG_METROS_POR_CAIXA: ${JADLOG_METROS_POR_CAIXA:-}
FREIGHT_PRODUCTION_DAYS: ${FREIGHT_PRODUCTION_DAYS:-0}
# Carts the Site priced are approved at checkout; larger ones wait for review.
QUOTE_AUTO_APPROVE: ${QUOTE_AUTO_APPROVE:-true}

View File

@@ -51,6 +51,8 @@ x-app-environment: &app-environment
# charges the larger of the real and the cubed weight. Both or neither.
JADLOG_CAIXA_CM: ${JADLOG_CAIXA_CM:-}
JADLOG_CUBAGEM_KG_M3: ${JADLOG_CUBAGEM_KG_M3:-}
# Metres of film one box holds; a longer order ships in more boxes.
JADLOG_METROS_POR_CAIXA: ${JADLOG_METROS_POR_CAIXA:-}
# Working days of production added to Jadlog's delivery time.
FREIGHT_PRODUCTION_DAYS: ${FREIGHT_PRODUCTION_DAYS:-0}
# A cart the Site priced is approved at checkout and can be paid at once;

View File

@@ -281,6 +281,11 @@ From the report already sent. These are dated promises, not backlog.
`JADLOG_CUBAGEM_KG_M3` make the quote send the larger of the real and the
cubed weight. The contract's factor is still unknown; until it is set the
Kanban's Frete card says the quote uses the real weight only.
**Corrected (2026-10-02):** the box is 63 × 15.5 × 15.5 cm (0.30 kg) and holds
about 60 m; UV ships in the same box at the same weight.
`JADLOG_METROS_POR_CAIXA` quotes a longer order as several boxes. Jadlog's
public .PACKAGE factor is 300 kg/m³ between states (167 within SP): 300 is
set, so in-state orders are quoted a little high, never low.
- `[~]` 1.3 — Idempotent Tiny/Olist order creation with order-number traceability.
Confirm endpoints, tag behaviour and rate limits first.
**Groundwork (2026-09-24), API v3 by decision:** OAuth2 against Tiny's

View File

@@ -124,10 +124,27 @@ class JadlogFreightTest(unittest.TestCase):
freight.quote('jadlog', '01310100', '60', 1490)
self.assertEqual(seen[1], 4.8)
def test_a_long_order_ships_in_more_boxes(self):
seen = []
def handler(request):
seen.append(json.loads(request.content)['frete'][0]['peso'])
return httpx.Response(200, json={'frete': [{'vltotal': 30, 'prazo': 3}]})
freight = self.freight(handler, JADLOG_PESO_BASE_KG='0.3', JADLOG_PESO_POR_METRO_KG='0.075',
JADLOG_CAIXA_CM='63x15,5x15,5', JADLOG_CUBAGEM_KG_M3='300',
JADLOG_METROS_POR_CAIXA='60')
# 63 x 15.5 x 15.5 cm is 0.01513575 m³: 4.541 kg cubed for one box.
self.assertEqual((freight.boxes('60'), freight.boxes('60.01'), freight.boxes('121')), (1, 2, 3))
quote = freight.quote('jadlog', '01310100', '61', 1490)
# Two boxes: 0.6 kg of packaging plus 4.575 kg of film, against 9.081 kg cubed.
self.assertEqual((quote['boxes'], quote['real_kg'], seen[0]), (2, '5.175', 9.081))
def test_a_box_needs_its_factor(self):
for env in ({'JADLOG_CAIXA_CM': '56x14x14'}, {'JADLOG_CUBAGEM_KG_M3': '300'},
{'JADLOG_CAIXA_CM': '56x14', 'JADLOG_CUBAGEM_KG_M3': '300'},
{'JADLOG_CAIXA_CM': '56x14x14', 'JADLOG_CUBAGEM_KG_M3': '0'}):
{'JADLOG_CAIXA_CM': '56x14x14', 'JADLOG_CUBAGEM_KG_M3': '0'},
{'JADLOG_METROS_POR_CAIXA': '0'}):
with self.subTest(env=env), self.assertRaises(RuntimeError):
self.freight(lambda request: httpx.Response(200), **env)
# Neither: the real weight only, as before the box was known.

View File

@@ -774,7 +774,8 @@ function renderIntegrations(){
// Jadlog charges the larger of the real and the cubed weight: without the
// box and the contract's factor, a light big box is quoted below its price.
const caixa=fr.box_cm?' Caixa '+fr.box_cm.map(n=>String(n).replace('.',',')).join(' × ')+' cm a '+
String(fr.cubage_kg_m3).replace('.',',')+' kg/m³ = '+kg(fr.cubed_kg)+' cubados; vale o maior dos dois pesos.'
String(fr.cubage_kg_m3).replace('.',',')+' kg/m³ = '+kg(fr.cubed_kg)+' cubados'+
(fr.metres_per_box?', até '+String(fr.metres_per_box).replace('.',',')+' m por caixa':'')+'; vale o maior dos dois pesos.'
:' Cubagem não configurada: a cotação usa só o peso real, e a Jadlog pode cobrar pelo tamanho da caixa.';
cards.push(fr.provider==='jadlog'
? integration('Frete',fr.box_cm?'Ativo':'Verificar',fr.box_cm?'ok':'warn','Entrega pela Jadlog e retirada em Franca. Pacote: '+kg(fr.base_kg)+