Skip to content

Commit

Permalink
[FIX] delivery_schenker: correct float_round return
Browse files Browse the repository at this point in the history
Because float_round as an example returns for 1.88 -> 1.880...01
we have to round it properly by float_repr and then parse it back to float
  • Loading branch information
mt-software-de committed Dec 12, 2023
1 parent 120e079 commit a57794a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
26 changes: 16 additions & 10 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 @@ -359,12 +359,22 @@ def _schenker_shipping_information_package_volume(self, picking, package):
]
)

def _float_round_repr(self, value, precision_digits, rounding_method="UP"):
return float_repr(
float_round(
value,
precision_digits=precision_digits,
rounding_method=rounding_method,
),
precision_digits=precision_digits,
)

def _schenker_shipping_information_round_weight(self, weight, precision_digits=2):
return float_round(weight, precision_digits=precision_digits)
return self._float_round_repr(weight, 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)
return self._float_round_repr(volume, precision_digits)

def _schenker_shipping_information_package(self, picking, package):
weight = package.shipping_weight or package.weight
Expand Down Expand Up @@ -449,20 +459,16 @@ def _schenker_measures(self, picking, vals):
:returns dict values for the proper unit key and value
"""
if self.schenker_measure_unit == "VOLUME":
return {
"measureUnitVolume": self._schenker_shipping_information_round_volume(
vals["shippingInformation"]["volume"]
)
}
return {"measureUnitVolume": vals["shippingInformation"]["volume"]}
return {}

def _schenker_get_total_shipping_volume(self, shipping_information):
volume = sum(info["volume"] for info in shipping_information)
volume = sum(float(info["volume"]) for info in shipping_information)
if float_compare(volume, 0, 3) <= 0:
raise UserError(
_("There is no volume set on the shipping package information")
)
return volume
return self._schenker_shipping_information_round_volume(volume)

def _prepare_schenker_shipping(self, picking):
"""Convert picking values for schenker api
Expand Down
14 changes: 7 additions & 7 deletions delivery_schenker/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def setUpClass(cls):
"name": "Test product",
"type": "product",
"weight": 1,
"volume": 1,
"volume": 1.875,
}
)
cls.sale, cls.picking = cls._create_sale_order(cls)
Expand Down Expand Up @@ -132,21 +132,21 @@ def _prepare_schenker_shipping(self, picking, vals=None):
"incotermLocation": "Test partner",
"productCode": "CON",
"measurementType": "METRIC",
"grossWeight": 1.0,
"grossWeight": "1.00",
"shippingInformation": {
"shipmentPosition": [
{
"dgr": False,
"cargoDesc": picking.name,
"grossWeight": 1.0,
"volume": 1.0,
"grossWeight": "1.00",
"volume": "1.88",
"packageType": "CI",
"stackable": False,
"pieces": 1,
}
],
"grossWeight": 1.0,
"volume": 1.0,
"grossWeight": "1.00",
"volume": "1.88",
},
"measureUnit": "VOLUME",
"customsClearance": False,
Expand All @@ -165,7 +165,7 @@ def _prepare_schenker_shipping(self, picking, vals=None):
"homeDelivery": True,
"ownPickup": True,
"pharmaceuticals": True,
"measureUnitVolume": 1.0,
"measureUnitVolume": "1.88",
}
res.update(vals)
return res

0 comments on commit a57794a

Please sign in to comment.