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
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:
@@ -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):
|
||||
|
||||
@@ -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'}
|
||||
|
||||
Reference in New Issue
Block a user