@@ -471,21 +471,31 @@ def scan_line(self, picking_id, barcode, confirm_pack_all=False, confirm_lot=Non
471
471
return self ._response_for_summary (picking )
472
472
473
473
# Search of the destination package
474
- search_result = self ._scan_line_find (picking , barcode )
475
- result_handler = getattr (self , "_select_lines_from_" + search_result .type )
476
- kw = {"confirm_pack_all" : confirm_pack_all , "confirm_lot" : confirm_lot }
477
- return result_handler (picking , selection_lines , search_result .record , ** kw )
474
+ handlers = {
475
+ "package" : self ._select_lines_from_package ,
476
+ "product" : self ._select_lines_from_product ,
477
+ "packaging" : self ._select_lines_from_packaging ,
478
+ "lot" : self ._select_lines_from_lot ,
479
+ "serial" : self ._select_lines_from_serial ,
480
+ "delivery_packaging" : self ._select_lines_from_delivery_packaging ,
481
+ "none" : self ._select_lines_from_none ,
482
+ }
483
+ search_result = self ._scan_line_find (picking , barcode , handlers .keys ())
484
+ # setting scanned record as kwarg in order to make better logs.
485
+ # The reason for this is that from a product we might select various records
486
+ # and lose track of what was initially scanned. This forces us to display
487
+ # standard messages that might have no meaning for the user.
488
+ kwargs = {
489
+ "confirm_pack_all" : confirm_pack_all ,
490
+ "confirm_lot" : confirm_lot ,
491
+ "scanned_record" : search_result .record ,
492
+ "barcode" : barcode ,
493
+ }
494
+ handler = handlers .get (search_result .type , self ._select_lines_from_none )
495
+ return handler (picking , selection_lines , search_result .record , ** kwargs )
478
496
479
- def _scan_line_find (self , picking , barcode , search_types = None ):
497
+ def _scan_line_find (self , picking , barcode , search_types ):
480
498
search = self ._actions_for ("search" )
481
- search_types = (
482
- "package" ,
483
- "product" ,
484
- "packaging" ,
485
- "lot" ,
486
- "serial" ,
487
- "delivery_packaging" ,
488
- )
489
499
return search .find (
490
500
barcode ,
491
501
types = search_types ,
@@ -508,15 +518,14 @@ def _select_lines_from_package(
508
518
lambda l : l .package_id == package and not l .shopfloor_checkout_done
509
519
)
510
520
if not lines :
511
- return self ._response_for_select_line (
512
- picking ,
513
- message = {
514
- "message_type" : "error" ,
515
- "body" : _ ("Package {} is not in the current transfer." ).format (
516
- package .name
517
- ),
518
- },
519
- )
521
+ # No line for scanned package in selected picking
522
+ # Check if there's any picking reserving this product.
523
+ return_picking = self ._get_pickings_for_package (package , limit = 1 )
524
+ if return_picking :
525
+ message = self .msg_store .reserved_for_other_picking_type (return_picking )
526
+ else :
527
+ message = self .msg_store .package_not_found_in_picking (package , picking )
528
+ return self ._response_for_select_line (picking , message = message )
520
529
self ._select_lines (lines , prefill_qty = prefill_qty )
521
530
if self .work .menu .no_prefill_qty :
522
531
lines = picking .move_line_ids
@@ -533,9 +542,12 @@ def _select_lines_from_product(
533
542
534
543
lines = selection_lines .filtered (lambda l : l .product_id == product )
535
544
if not lines :
536
- return self ._response_for_select_line (
537
- picking , message = self .msg_store .product_not_found_in_current_picking ()
538
- )
545
+ return_picking = self ._get_pickings_for_product (product , limit = 1 )
546
+ if return_picking :
547
+ message = self .msg_store .reserved_for_other_picking_type (return_picking )
548
+ else :
549
+ message = self .msg_store .product_not_found_in_current_picking (product )
550
+ return self ._response_for_select_line (picking , message = message )
539
551
540
552
# When products are as units outside of packages, we can select them for
541
553
# packing, but if they are in a package, we want the user to scan the packages.
@@ -1047,18 +1059,21 @@ def scan_package_action(self, picking_id, selected_line_ids, barcode):
1047
1059
return self ._response_for_select_document (message = message )
1048
1060
1049
1061
selected_lines = self .env ["stock.move.line" ].browse (selected_line_ids ).exists ()
1050
- search_result = self ._scan_package_find (picking , barcode )
1051
- message = self ._check_scan_package_find (picking , search_result )
1052
- if message :
1053
- return self ._response_for_select_package (
1054
- picking ,
1055
- selected_lines ,
1056
- message = message ,
1057
- )
1058
- result_handler = getattr (
1059
- self , "_scan_package_action_from_" + search_result .type
1060
- )
1061
- return result_handler (picking , selected_lines , search_result .record )
1062
+ handlers = {
1063
+ "package" : self ._scan_package_action_from_package ,
1064
+ "product" : self ._scan_package_action_from_product ,
1065
+ "packaging" : self ._scan_package_action_from_packaging ,
1066
+ "lot" : self ._scan_package_action_from_lot ,
1067
+ "serial" : self ._scan_package_action_from_serial ,
1068
+ "delivery_packaging" : self ._scan_package_action_from_delivery_packaging ,
1069
+ }
1070
+ search_result = self ._scan_package_find (picking , barcode , handlers .keys ())
1071
+ handler = handlers .get (search_result .type , self ._scan_package_action_from_none )
1072
+ kwargs = {
1073
+ "barcode" : barcode ,
1074
+ "scanned_record" : search_result .record ,
1075
+ }
1076
+ return handler (picking , selected_lines , search_result .record , ** kwargs )
1062
1077
1063
1078
def _scan_package_find (self , picking , barcode , search_types = None ):
1064
1079
search = self ._actions_for ("search" )
@@ -1079,10 +1094,6 @@ def _scan_package_find(self, picking, barcode, search_types=None):
1079
1094
),
1080
1095
)
1081
1096
1082
- def _check_scan_package_find (self , picking , search_result ):
1083
- # Used by inheriting modules
1084
- return False
1085
-
1086
1097
def _find_line_to_increment (self , product_lines ):
1087
1098
"""Find which line should have its qty incremented.
1088
1099
0 commit comments