@@ -224,15 +224,15 @@ def _prepare_attributes(
224
224
and pack .package_type_id
225
225
or picking .carrier_id .postlogistics_default_package_type_id
226
226
)
227
- services = package_type ._get_shipper_package_code_list ()
227
+ package_codes = package_type ._get_shipper_package_code_list ()
228
228
229
229
if pack_weight :
230
230
total_weight = pack_weight
231
231
else :
232
232
total_weight = pack .shipping_weight if pack else picking .shipping_weight
233
233
total_weight *= 1000
234
234
235
- if not services :
235
+ if not package_codes :
236
236
raise UserError (
237
237
picking .env ._ (
238
238
"No PostLogistics packaging services found "
@@ -243,51 +243,51 @@ def _prepare_attributes(
243
243
# Activate phone notification ZAW3213
244
244
# if phone call notification is set on partner
245
245
if picking .partner_id .postlogistics_notification == "phone" :
246
- services .append ("ZAW3213" )
246
+ package_codes .append ("ZAW3213" )
247
247
248
248
attributes = {
249
249
"weight" : int (total_weight ),
250
250
}
251
251
252
252
# Remove the services if the delivery fixed date is not set
253
- if "ZAW3217" in services :
253
+ if "ZAW3217" in package_codes :
254
254
if picking .delivery_fixed_date :
255
255
attributes ["deliveryDate" ] = picking .delivery_fixed_date
256
256
else :
257
- services .remove ("ZAW3217" )
257
+ package_codes .remove ("ZAW3217" )
258
258
259
259
# parcelNo / parcelTotal cannot be used if service ZAW3218 is not activated
260
- if "ZAW3218" in services :
260
+ if "ZAW3218" in package_codes :
261
261
if pack_total > 1 :
262
262
attributes .update (
263
263
{"parcelTotal" : pack_total - 1 , "parcelNo" : pack_num - 1 }
264
264
)
265
265
else :
266
- services .remove ("ZAW3218" )
266
+ package_codes .remove ("ZAW3218" )
267
267
268
- if "ZAW3219" in services and picking .delivery_place :
268
+ if "ZAW3219" in package_codes and picking .delivery_place :
269
269
attributes ["deliveryPlace" ] = picking .delivery_place
270
270
if picking .carrier_id .postlogistics_proclima_logo :
271
271
attributes ["proClima" ] = True
272
272
else :
273
273
attributes ["proClima" ] = False
274
274
275
- attributes ["przl" ] = services
275
+ attributes ["przl" ] = package_codes
276
276
277
277
return attributes
278
278
279
- def _get_itemid (self , picking , pack_no ):
279
+ def _get_itemid (self , picking , package ):
280
280
"""Allowed characters are alphanumeric plus `+`, `-` and `_`
281
281
Last `+` separates picking name and package number (if any)
282
282
283
283
:return string: itemid
284
284
285
285
"""
286
286
name = _compile_itemid .sub ("" , picking .name )
287
- if not pack_no :
287
+ if not package :
288
288
return name
289
289
290
- pack_no = _compile_itemid .sub ("" , pack_no )
290
+ pack_no = _compile_itemid .sub ("" , package . name )
291
291
codes = [name , pack_no ]
292
292
return "+" .join (c for c in codes if c )
293
293
@@ -312,7 +312,7 @@ def _get_item_additional_data(self, picking, package=None):
312
312
result += cod_attributes
313
313
return result
314
314
315
- def _get_item_number (self , picking , pack_num ):
315
+ def _get_item_number (self , picking , package ):
316
316
"""Generate the tracking reference for the last 8 digits
317
317
of tracking number of the label.
318
318
@@ -322,15 +322,14 @@ def _get_item_number(self, picking, pack_num):
322
322
e.g. 03000042 for 3rd pack of picking OUT/19000042
323
323
"""
324
324
picking_num = _compile_itemnum .sub ("" , picking .name )
325
- return "%02d%s" % (pack_num , picking_num [- 6 :].zfill (6 ))
325
+ return "%02d%s" % (package . name , picking_num [- 6 :].zfill (6 ))
326
326
327
327
def _prepare_item_list (self , picking , recipient , packages ):
328
328
"""Return a list of item made from the pickings"""
329
329
carrier = picking .carrier_id
330
330
item_list = []
331
- pack_counter = 1
332
331
333
- def add_item (package = None ):
332
+ def add_item (counter = 1 , package = None ):
334
333
assert picking or package
335
334
itemid = self ._get_itemid (picking , package .name if package else None )
336
335
item = {
@@ -345,7 +344,7 @@ def add_item(package=None):
345
344
picking_num = _compile_itemnum .sub ("" , picking .name )
346
345
item_number = f"9{ picking_num [- 7 :].zfill (7 )} "
347
346
else :
348
- item_number = self ._get_item_number (picking , pack_counter )
347
+ item_number = self ._get_item_number (picking , counter )
349
348
item ["itemNumber" ] = item_number
350
349
351
350
additional_data = self ._get_item_additional_data (picking , package = package )
@@ -354,18 +353,15 @@ def add_item(package=None):
354
353
355
354
item_list .append (item )
356
355
357
- if not packages :
358
- attributes = self ._prepare_attributes (picking )
359
- add_item ()
360
- return item_list
361
-
362
- pack_total = len (packages )
363
- for pack in packages :
356
+ total_packages = len (packages )
357
+ for index , package in enumerate (packages ):
364
358
attributes = self ._prepare_attributes (
365
- picking , pack , pack_counter , pack_total
359
+ picking , package , index , total_packages
366
360
)
367
- add_item (package = pack )
368
- pack_counter += 1
361
+ add_item (counter = index , package = package )
362
+ else :
363
+ attributes = self ._prepare_attributes (picking )
364
+ add_item ()
369
365
return item_list
370
366
371
367
def _prepare_label_definition (self , picking ):
0 commit comments