@@ -352,9 +352,14 @@ private void setScannedCodeForEntry(Entry entry, ScannableCode scannedCode) {
352352 notifyQuantityChanged (this , entry .product );
353353 }
354354
355+ private String findCodeByScannedCode (Product product , ScannableCode scannableCode ) {
356+ String code = findCodeByScannedCodeInternal (product , scannableCode , true );
357+ return code != null ? code : scannableCode .getCode ();
358+ }
359+
355360 // finds the code matching the code in the product if it was scanned with leading zeros
356361 // and the leading zeros are missing in the scannableCodes of the product
357- private String findCodeByScannedCode (Product product , ScannableCode scannableCode ) {
362+ private String findCodeByScannedCodeInternal (Product product , ScannableCode scannableCode , boolean recursive ) {
358363 String scannedCode = scannableCode .getCode ();
359364
360365 for (String code : product .getScannableCodes ()) {
@@ -363,15 +368,17 @@ private String findCodeByScannedCode(Product product, ScannableCode scannableCod
363368 }
364369 }
365370
366- if (scannedCode .length () > 0 && scannedCode .startsWith ("0" )) {
367- scannedCode = scannedCode .substring (1 , scannedCode .length ());
368- return findCodeByScannedCode (product , ScannableCode .parse (project , scannedCode ));
369- } else if (scannedCode .length () < 13 ) {
370- scannedCode = StringUtils .repeat ('0' , 13 - scannedCode .length ()) + scannedCode ;
371- return findCodeByScannedCode (product , ScannableCode .parse (project , scannedCode ));
371+ if (recursive ) {
372+ if (scannedCode .length () > 0 && scannedCode .startsWith ("0" )) {
373+ scannedCode = scannedCode .substring (1 , scannedCode .length ());
374+ return findCodeByScannedCodeInternal (product , ScannableCode .parse (project , scannedCode ), true );
375+ } else if (scannedCode .length () < 13 ) {
376+ scannedCode = StringUtils .repeat ('0' , 13 - scannedCode .length ()) + scannedCode ;
377+ return findCodeByScannedCodeInternal (product , ScannableCode .parse (project , scannedCode ), false );
378+ }
372379 }
373380
374- return scannedCode ;
381+ return null ;
375382 }
376383
377384 private int indexOf (Entry e ) {
0 commit comments