diff --git a/inema/wpint.py b/inema/wpint.py index 2b53683..9e1dc5d 100644 --- a/inema/wpint.py +++ b/inema/wpint.py @@ -185,10 +185,20 @@ class WarenpostInt(object): desc=None): """Build an 'content item' in the language of the WaPoInt API. Represents one line on the customs form.""" + line_weight_g = int(line_weight_g) + if line_weight_g > 2000: + raise ValueError('Maximum line weight is 2000g') + qty = int(qty) + if qty > 99 or qty < 1: + raise ValueError('Maximum line quantity is 99') + if desc and len(desc) > 33: + raise ValueError('Maximum length of contentPieceDescription is 33 chars') + if hs_code and (len(hs_code) < 4 or len(hs_code) > 10): + raise ValueError('HS-Code must be between 4 and 10 characters long') ret = { 'contentPieceNetweight': line_weight_g, - 'contentPieceValue': str(int(line_value)), - 'contentPieceAmount': int(qty), + 'contentPieceValue': "%.2f" % (line_value), + 'contentPieceAmount': qty, } if hs_code: ret['contentPieceHsCode'] = str(hs_code) @@ -201,12 +211,17 @@ class WarenpostInt(object): def build_item(self, product, sender, recipient, weight_grams, amount=0, currency='EUR', contents=None): """Build an 'item' in the language of the WaPoInt API. Represents one shipment.""" + weight_grams = int(weight_grams) + if weight_grams > 2000: + raise ValueError('Maximum item gross weight is 2000g') + if len(currency) != 3: + raise ValueError('Currency must be expressed as 3-digit ISO-4217 code') ret = { 'product': str(product), 'serviceLevel': 'STANDARD', 'shipmentAmount': int(amount), 'shipmentCurrency': currency, - 'shipmentGrossWeight': int(weight_grams), + 'shipmentGrossWeight': weight_grams, 'shipmentNaturetype': 'SALE_GOODS', } # merge in the sender and recipient fields