@@ -211,9 +211,16 @@ def get_date_from_field(*args):
211
211
return res
212
212
213
213
214
- def convert_unit_code (key , val ):
214
+ def convert_unit_code (key , val , unit_mapping = None ):
215
215
if key in LST_FIELD_UNIT_CODE :
216
- return MAPPING_UNITCODE_UBL_TO_WAMAS ["unitCode" ].get (val , val )
216
+ MAPPING = (
217
+ unit_mapping
218
+ and unit_mapping .get (
219
+ "MAPPING_UNITCODE_UBL_TO_WAMAS" , MAPPING_UNITCODE_UBL_TO_WAMAS
220
+ )
221
+ or MAPPING_UNITCODE_UBL_TO_WAMAS
222
+ )
223
+ return MAPPING ["unitCode" ].get (val , val )
217
224
return val
218
225
219
226
@@ -327,7 +334,8 @@ def generate_wamas_line(dict_item, grammar, **kwargs): # noqa: C901
327
334
328
335
val = globals ()[df_func ](* args )
329
336
330
- val = convert_unit_code (_key , val )
337
+ extra_data = kwargs .get ("extra_data" , None )
338
+ val = convert_unit_code (_key , val , unit_mapping = extra_data )
331
339
if kwargs .get ("check_to_set_value_to_string" , False ):
332
340
# Ignore convert string of float/int/date/datetime type
333
341
# to move entire value when convert wamas2wamas
@@ -352,16 +360,20 @@ def generate_wamas_line(dict_item, grammar, **kwargs): # noqa: C901
352
360
return res
353
361
354
362
355
- def generate_wamas_lines (dict_input , telegram_type , line_idx , wamas_lines ):
363
+ def generate_wamas_lines (
364
+ dict_input , telegram_type , line_idx , wamas_lines , extra_data = False
365
+ ):
356
366
line_idx += 1
357
367
grammar = DICT_WAMAS_GRAMMAR [telegram_type .lower ()]
358
- line = generate_wamas_line (dict_input , grammar , line_idx = line_idx )
368
+ line = generate_wamas_line (
369
+ dict_input , grammar , line_idx = line_idx , extra_data = extra_data
370
+ )
359
371
if line :
360
372
wamas_lines .append (line )
361
373
return line_idx , wamas_lines
362
374
363
375
364
- def dict2wamas (dict_input , telegram_type ):
376
+ def dict2wamas (dict_input , telegram_type , extra_data = False ):
365
377
wamas_lines = []
366
378
lst_telegram_type = telegram_type .split ("," )
367
379
@@ -375,16 +387,16 @@ def dict2wamas(dict_input, telegram_type):
375
387
# 1 line for `KstAus_LagIdKom = kMEZ`
376
388
dict_input ["picking_zone" ] = "kMEZ"
377
389
line_idx , wamas_lines = generate_wamas_lines (
378
- dict_input , telegram_type , line_idx , wamas_lines
390
+ dict_input , telegram_type , line_idx , wamas_lines , extra_data = extra_data
379
391
)
380
392
# 1 line for `KstAus_LagIdKom = kPAR`
381
393
dict_input ["picking_zone" ] = "kPAR"
382
394
line_idx , wamas_lines = generate_wamas_lines (
383
- dict_input , telegram_type , line_idx , wamas_lines
395
+ dict_input , telegram_type , line_idx , wamas_lines , extra_data = extra_data
384
396
)
385
397
else :
386
398
line_idx , wamas_lines = generate_wamas_lines (
387
- dict_input , telegram_type , line_idx , wamas_lines
399
+ dict_input , telegram_type , line_idx , wamas_lines , extra_data = extra_data
388
400
)
389
401
return "\n " .join (wamas_lines ).encode ("iso-8859-1" )
390
402
@@ -510,13 +522,20 @@ def wamas2dict(
510
522
511
523
def dict2ubl (template , data , verbose = False , extra_data = False ):
512
524
t = miniqweb .QWebXml (template )
525
+ MAPPING = (
526
+ extra_data
527
+ and extra_data .get (
528
+ "MAPPING_UNITCODE_WAMAS_TO_UBL" , MAPPING_UNITCODE_WAMAS_TO_UBL
529
+ )
530
+ or MAPPING_UNITCODE_WAMAS_TO_UBL
531
+ )
513
532
# Convert dict to object to use dotted notation in template
514
533
globals_dict = {
515
534
"record" : obj (data ),
516
535
"get_date" : get_date ,
517
536
"get_time" : get_time ,
518
537
"get_current_date" : get_current_date ,
519
- "MAPPING" : MAPPING_UNITCODE_WAMAS_TO_UBL ,
538
+ "MAPPING" : MAPPING ,
520
539
"extra_data" : extra_data ,
521
540
}
522
541
xml = t .render (globals_dict )
0 commit comments