Skip to content

Commit

Permalink
[FIX] delivery_schenker: round up package volume
Browse files Browse the repository at this point in the history
The Schenker API requires a volume to be non-zero, but also forces 2 decimal places.
The 0.01 minimum was removed for avoiding fake volumes when incorrectly configured, but we must still round up cases where the volume is non-zero but rounds to 0.00.
It is also logical to give an overestimate on the volume to the carrier, rather than an underestimate.

round -> repr -> float to avoid Python floating decimals that error when validating with the Schema.
float_round(2.086, precision_digits=2) = 2.0100000000000002
float_repr(float_round(2.086, precision_digits=2), 2) = '2.01' (string)
float(float_repr(float_round(2.086, precision_digits=2), 2)) = 2.01
  • Loading branch information
hildickethan committed Jul 25, 2023
1 parent 5bbe5c0 commit 3fbd67b
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions delivery_schenker/models/delivery_carrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_compare, float_round
from odoo.tools import float_compare, float_repr, float_round

from .schenker_request import SchenkerRequest

Expand Down Expand Up @@ -362,8 +362,20 @@ def _schenker_shipping_information_round_weight(self, weight, precision_digits=2
return float_round(weight, precision_digits=precision_digits)

def _schenker_shipping_information_round_volume(self, volume, precision_digits=2):
"""The schenker api requires 2 decimal points"""
return float_round(volume, precision_digits=precision_digits)
"""
The schenker api requires 2 decimal points.
Round up to avoid 0 if <0.005.
round -> repr -> float to avoid extra decimals that error with the Schema.
float_round(2.086, precision_digits=2) = 2.0100000000000002
"""
return float(
float_repr(
float_round(
volume, precision_digits=precision_digits, rounding_method="UP"
),
precision_digits=precision_digits,
)
)

def _schenker_shipping_information_package(self, picking, package):
weight = package.shipping_weight or package.weight
Expand Down

0 comments on commit 3fbd67b

Please sign in to comment.