changeset 420bd2958314 in modules/stock_package_shipping_dpd:5.6
details:
https://hg.tryton.org/modules/stock_package_shipping_dpd?cmd=changeset;node=420bd2958314
description:
Set only non required parcel field when possible
We must fill only when it is not empty.
issue9907
review329811002
(grafted from c67786900657d57b1e936daadeb5a9fd244e0e45)
diffstat:
stock.py | 31 +++++++++++++++++++------------
1 files changed, 19 insertions(+), 12 deletions(-)
diffs (42 lines):
diff -r d92cb24be4ae -r 420bd2958314 stock.py
--- a/stock.py Fri Dec 11 15:44:43 2020 +0100
+++ b/stock.py Wed Dec 16 20:42:56 2020 +0100
@@ -193,19 +193,26 @@
cm = UoM(ModelData.get_id('product', 'uom_centimeter'))
- parcel = {
- 'customerReferenceNumber1': package.code,
- 'weight': int(package.total_weight * 10) * 10
- }
+ parcel = {}
+
+ if package.total_weight:
+ # in grams rounded in 10 gram units
+ weight = int(package.total_weight * 10) * 10
+ if weight < 1000000000:
+ parcel['weight'] = weight
- length = UoM.compute_qty(
- package.type.length_uom, package.type.length, cm)
- width = UoM.compute_qty(
- package.type.width_uom, package.type.width, cm)
- height = UoM.compute_qty(
- package.type.height_uom, package.type.height, cm)
- if length < 1000 and width < 1000 and height < 1000:
- parcel['volume'] = '%03i%03i%03i' % (length, width, height)
+ if (package.type.length is not None
+ and package.type.width is not None
+ and package.type.height is not None):
+ length = UoM.compute_qty(
+ package.type.length_uom, package.type.length, cm)
+ width = UoM.compute_qty(
+ package.type.width_uom, package.type.width, cm)
+ height = UoM.compute_qty(
+ package.type.height_uom, package.type.height, cm)
+ if length < 1000 and width < 1000 and height < 1000:
+ parcel['volume'] = int(
+ '%03i%03i%03i' % (length, width, height))
return parcel