Skip to content

Commit

Permalink
StepComXMLDesadvBean and CompuDataDesadvBean: don't remove leading 0s (
Browse files Browse the repository at this point in the history
…#10481)

also div minor fixes in metasfresh
  • Loading branch information
metas-ts committed Jan 4, 2021
1 parent 3e38a20 commit e7ef903
Show file tree
Hide file tree
Showing 12 changed files with 58 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static String[] split(String searchIn, String splitter) {
}

/**
* Remove String toBeRemoved from oroginal
* Remove String toBeRemoved from original
* @param original String to look in
* @param toBeRemoved String to get removed
* @param ignoreCase should we take care of case
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@
*/
public interface IAttributeValueGenerator extends IAttributeValueHandler
{

/**
*
* See X_M_Attribute.ATTRIBUTEVALUETYPE_*.
*
* @return value type or null if information is not not available
Expand All @@ -58,9 +56,6 @@ public interface IAttributeValueGenerator extends IAttributeValueHandler
*
* NOTE: {@link #generateAttributeValue(Properties, int, int, boolean, String)} is NOT considered.
*
* @param ctx
* @param attributeSet
* @param attribute
* @return true if a value can be generated
*/
boolean canGenerateValue(Properties ctx, IAttributeSet attributeSet, I_M_Attribute attribute);
Expand All @@ -79,7 +74,6 @@ public interface IAttributeValueGenerator extends IAttributeValueHandler
/**
* Generate a numeric value. Will throw {@link UnsupportedOperationException} for attributes of different types.
*
* @param ctx
* @param attributeSet attribute set
* @param attribute attribute on which the value will be generated
* @return generated numeric value
Expand All @@ -90,7 +84,6 @@ public interface IAttributeValueGenerator extends IAttributeValueHandler
/**
* Generate a date value. Will throw {@link UnsupportedOperationException} for attributes of different types.
*
* @param ctx
* @param attributeSet attribute set
* @param attribute attribute on which the value will be generated
* @return generated date value
Expand All @@ -103,12 +96,8 @@ public interface IAttributeValueGenerator extends IAttributeValueHandler
*
* Will be specific for each implementation. Will throw {@link UnsupportedOperationException} for attributes of different types.
*
* @param ctx
* @param tableId
* @param recordId
* @param isSOTrx implementors might return different values for sales and purchase transactions
* @param trxName
* @return
*
* @throws UnsupportedOperationException if value cannot be generated
*/
AttributeListValue generateAttributeValue(Properties ctx, int tableId, int recordId, boolean isSOTrx, String trxName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ private void addPackRecordsToLineUsingJustInOutLine(
private String computeSSCC18(@NonNull final OrgId orgId)
{
final SSCC18 sscc18 = sscc18CodeService.generate(orgId);
return sscc18CodeService.toString(sscc18, false);
return sscc18.asString();
}

private StockQtyAndUOMQty addPackRecordToLineUsingHU(
Expand Down Expand Up @@ -674,7 +674,7 @@ private void extractAndSetPackagingGTINs(
private String computeSSCC18ForHUId(@NonNull final OrgId orgId, @NonNull final HuId huId)
{
final SSCC18 sscc18 = sscc18CodeService.generate(orgId, huId.getRepoId());
return sscc18CodeService.toString(sscc18, false);
return sscc18.asString();
}

private I_EDI_DesadvLine_Pack createNewPackRecord(@NonNull final I_EDI_DesadvLine desadvLineRecord)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
import lombok.NonNull;

/**
* Producer which is used to generate {@link I_EDI_DesadvLine_SSCC} labels and print them.
* Producer which is used to generate {@link I_EDI_DesadvLine_Pack}s labels and print them.
*
* @author tsa
*
Expand All @@ -69,7 +69,7 @@ public class DesadvLineSSCC18Generator

//
// status
/** {@link I_EDI_DesadvLine_SSCC} IDs to print */
/** {@link I_EDI_DesadvLine_Pack} IDs to print */
private final Set<Integer> desadvLineSSCC_IDs_ToPrint = new LinkedHashSet<>();

public DesadvLineSSCC18Generator(@NonNull final SSCC18CodeBL sscc18CodeService)
Expand All @@ -78,7 +78,7 @@ public DesadvLineSSCC18Generator(@NonNull final SSCC18CodeBL sscc18CodeService)
}

/**
* Generates {@link I_EDI_DesadvLine_SSCC} records until {@link IPrintableDesadvLineSSCC18Labels#getRequiredSSCC18sCount()} is fulfilled.
* Generates {@link I_EDI_DesadvLine_Pack} records until {@link IPrintableDesadvLineSSCC18Labels#getRequiredSSCC18sCount()} is fulfilled.
*
* It will enqueue the SSCC18 labels to be printed.
* To actually print the labels, call {@link #printAll()}.
Expand Down Expand Up @@ -126,7 +126,7 @@ public DesadvLineSSCC18Generator generateAndEnqueuePrinting(@NonNull final IPrin
}

/**
* Generates {@link I_EDI_DesadvLine_SSCC} records until {@link IPrintableDesadvLineSSCC18Labels#getRequiredSSCC18sCount()} is fullfilled.
* Generates {@link I_EDI_DesadvLine_Pack} records until {@link IPrintableDesadvLineSSCC18Labels#getRequiredSSCC18sCount()} is fullfilled.
*
* It will enqueue the SSCC18 labels to be printed.
* To actually print the labels, call {@link #printAll()}.
Expand Down Expand Up @@ -214,12 +214,9 @@ public DesadvLineSSCC18Generator setPrintExistingLabels(final boolean printExist
}

/**
* Creates a new {@link I_EDI_DesadvLine_SSCC} record.
* Creates a new {@link I_EDI_DesadvLine_Pack} record.
*
* The SSCC18 code will be generated.
*
* @param desadvLineLabels
* @return created {@link I_EDI_DesadvLine_SSCC}.
*/
private final I_EDI_DesadvLine_Pack generateDesadvLineSSCC(final I_EDI_DesadvLine desadvLine, final LUQtys luQtys)
{
Expand All @@ -230,7 +227,7 @@ private final I_EDI_DesadvLine_Pack generateDesadvLineSSCC(final I_EDI_DesadvLin
//
// Generate the actual SSCC18 number and update the SSCC record
final SSCC18 sscc18 = sscc18CodeBL.generate(OrgId.ofRepoId(desadvLine.getAD_Org_ID()));
final String ipaSSCC18 = sscc18CodeBL.toString(sscc18, false); // humanReadable=false
final String ipaSSCC18 = sscc18.asString(); // humanReadable=false

//
// Create SSCC record
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private void setupHandlingUnit()
final I_M_HU_Attribute huAttrRecord = newInstance(I_M_HU_Attribute.class);
huAttrRecord.setM_Attribute_ID(sscc18HUPIAttributeRecord.getM_Attribute_ID());
huAttrRecord.setM_HU_ID(lu.getM_HU_ID());
huAttrRecord.setValue(sscc18CodeBL.toString(sscc18CodeBL.generate(OrgId.ANY), false));
huAttrRecord.setValue(sscc18CodeBL.generate(OrgId.ANY).asString());
huAttrRecord.setM_HU_PI_Attribute_ID(sscc18HUPIAttributeRecord.getM_HU_PI_Attribute_ID());
saveRecord(huAttrRecord);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ public interface ISSCC18CodeBL extends ISingletonService
*/
SSCC18 generate(OrgId orgId);

/**
* Converts given {@link SSCC18} code to String representation
*
* @return SSCC18 string representation
*/
String toString(SSCC18 sscc18, boolean humanReadable);

/**
* From the right to left, start with odd position, assign the odd/even position to each digit. Sum all digits in odd position and multiply the result by 3. Sum all digits in even position. Sum
* the results of step 3 and step 4. Divide the result of step 4 by 10. The check digit is the number which adds the remainder to 10.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,52 @@
* #L%
*/


import lombok.NonNull;
import lombok.Value;
import org.adempiere.util.lang.ObjectUtils;

/**
* Immutable POJO for Serial Shipping Container Code (SSCC-18)
*
* @See <a href="http://mdn.morovia.com/kb/Serial-Shipping-Container-Code-SSCC18-10601.html">SSCC18</a>
* <p>
* See <a href="http://mdn.morovia.com/kb/Serial-Shipping-Container-Code-SSCC18-10601.html">SSCC18</a>
*/
@Value
public class SSCC18
{

/**
* Extended digit and assigned by the company
*/
private final int extensionDigit;
int extensionDigit;

/**
* The manufacturer code (or company code) is assigned by GS1 (formerly known as UCC/EAN organization)
*/
private final String manufacturerCode;
String manufacturerCode;

/**
* Identifies this merchandise container and assigned by the manufacturer.
*
* <p>
* The manufacturer should not reuse the serial number within a certain time frame, for example, 1 year.
*
* <p>
* The company code normally comprises 7 or 8 digits. Therefore, the serial number can be 9 or 8 digits.
*/
private final String serialNumber;
String serialNumber;

/**
* SSCC-18 check digit to ensure that the data is correctly entered. It is part of the data encoded into the barcode. A receiving system is required to validate this check digit, so you should get
* it correct at the first place.
*/
private final int checkDigit;
int checkDigit;

public SSCC18(final int extensionDigit
, final String manufacturerCode
, final String serialNumber
, final int checkDigit)
public SSCC18(final int extensionDigit,
@NonNull final String manufacturerCode,
@NonNull final String serialNumber,
final int checkDigit)
{
this.extensionDigit = extensionDigit;
this.manufacturerCode = manufacturerCode;
this.serialNumber = serialNumber;
this.manufacturerCode = manufacturerCode.trim();
this.serialNumber = serialNumber.trim();
this.checkDigit = checkDigit;
}

Expand Down Expand Up @@ -94,4 +96,15 @@ public int getCheckDigit()
{
return checkDigit;
}

/**
* @return SSCC18 string representation
*/
public String asString()
{
return getExtensionDigit()
+ getManufacturerCode()
+ getSerialNumber()
+ getCheckDigit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
public class SSCC18AttributeValueGenerator extends AbstractAttributeValueGenerator
{

private ISSCC18CodeBL sscc18CodeBL = Services.get(ISSCC18CodeBL.class);

@Override
public String getAttributeValueType()
{
Expand All @@ -60,13 +62,12 @@ public String generateStringValue(
final I_M_Attribute attribute_IGNORED)
{
final I_M_HU hu = Services.get(IHUAttributesBL.class).getM_HU(attributeSet);
final ISSCC18CodeBL creator = Services.get(ISSCC18CodeBL.class);

// We use M_HU_ID for SSCC18 serial number (06852)
final int serialNumber = hu.getM_HU_ID();
Check.errorIf(serialNumber <= 0, "M_HU_ID={} for M_HU={}", serialNumber, hu);

final SSCC18 sscc18 = creator.generate(OrgId.ofRepoIdOrAny(hu.getAD_Org_ID()), serialNumber);
return creator.toString(sscc18, false); // humanReadable=false
final SSCC18 sscc18 = sscc18CodeBL.generate(OrgId.ofRepoIdOrAny(hu.getAD_Org_ID()), serialNumber);
return sscc18.asString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class SSCC18CodeBL implements ISSCC18CodeBL

private final NextSerialNumberProvider nextSerialNumberProvider;
/** for debugging */
private boolean hasCustomNextSerialNumberProvider;
private final boolean hasCustomNextSerialNumberProvider;

public SSCC18CodeBL()
{
Expand Down Expand Up @@ -206,7 +206,7 @@ public void validate(final SSCC18 sscc18ToValidate)
Check.errorIf(serialNumber.length() > digitsAvailableForSerialNumber, "With a {}-digit manufactoring code={}, the serial number={} may only have {} digits", manufactCode.length(), manufactCode, serialNumber, digitsAvailableForSerialNumber);

final int computeCheckDigit = computeCheckDigit(sscc18ToValidate);
Check.errorUnless(sscc18ToValidate.getCheckDigit() == computeCheckDigit, "The check digit of SSCC18={} is not valid; It needs to be={}", toString(sscc18ToValidate, false), computeCheckDigit);
Check.errorUnless(sscc18ToValidate.getCheckDigit() == computeCheckDigit, "The check digit of SSCC18={} is not valid; It needs to be={}", sscc18ToValidate.asString(), computeCheckDigit);
Check.errorUnless(isCheckDigitValid(sscc18ToValidate), "Check digit is not valid");
}

Expand All @@ -219,8 +219,7 @@ private int validateSerialNumber(final String manufactCode, final String serialN

private int computeLenghtOfSerialNumber(final String manufactCode)
{
final int digitsAvailableForSerialNumber = 18 - 1/* extension-digit */ - manufactCode.length() - 1/* check-digit */;
return digitsAvailableForSerialNumber;
return 18 - 1/* extension-digit */ - manufactCode.length() - 1;
}

private void validateManufacturerCode(@NonNull final String manufactCode)
Expand All @@ -229,22 +228,6 @@ private void validateManufacturerCode(@NonNull final String manufactCode)
Check.errorIf(manufactCode.length() > 9, "The manufacturer code " + manufactCode + " is too long");
}

@Override
public String toString(@NonNull final SSCC18 sscc18, final boolean humanReadable)
{
if (!humanReadable)
{
return sscc18.getExtensionDigit()
+ sscc18.getManufacturerCode()
+ sscc18.getSerialNumber()
+ sscc18.getCheckDigit();
}
else
{
throw new IllegalStateException("Not implemented");
}
}

@FunctionalInterface
public interface NextSerialNumberProvider
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public void testGenerateSSCC18value79()

final SSCC18 generatedSSCC18 = sscc18CodeBL.generate(OrgId.ANY, 1000000);

assertThat(generatedSSCC18.asString()).hasSize(18);
Assert.assertEquals("Serial number is not correct",
"001000000", // expected,
generatedSSCC18.getSerialNumber() // actual
Expand All @@ -133,6 +134,7 @@ public void testGenerateSSCC18value55()

final SSCC18 generatedSSCC18 = sscc18CodeBL.generate(OrgId.ANY, 1000000);

assertThat(generatedSSCC18.asString()).hasSize(18);
Assert.assertEquals("Serial number is not correct",
"001000000", // expected,
generatedSSCC18.getSerialNumber() // actual
Expand All @@ -145,6 +147,7 @@ public void testGenerateSSCC18value11()
setManufacturerCode("2");

final SSCC18 generatedSSCC18 = sscc18CodeBL.generate(OrgId.ANY, 1000000);
assertThat(generatedSSCC18.asString()).hasSize(18);

Assert.assertEquals("Serial number is not correct",
"001000000", // expected,
Expand All @@ -163,18 +166,22 @@ public void testGenerateSSCC18value9DigitManufacturerCode()
setManufacturerCode("123456789");
final SSCC18CodeBL sscc18CodeBL = new SSCC18CodeBL(orgId -> 23);
final SSCC18 generatedSSCC18 = sscc18CodeBL.generate(OrgId.ANY);
assertThat(sscc18CodeBL.toString(generatedSSCC18, false)).hasSize(18).isEqualTo("012345678900000234");

// then
assertThat(generatedSSCC18.asString()).hasSize(18).isEqualTo("012345678900000234");
}

@Test
public void testcheckValidSSCC18() // NOPMD by ts on 26.07.13 15:15 OK, method under test is expected to just return without exception
public void testcheckValidSSCC18()
{
final String manufacturerCode = "0718908 ";
final String serialNumber = "562723189";
final int checkDigit = 6;
final int extensionDigit = 0;

final SSCC18 sscc18ToValidate = new SSCC18(extensionDigit, manufacturerCode, serialNumber, checkDigit);
assertThat(sscc18ToValidate.asString()).hasSize(18);

sscc18CodeBL.validate(sscc18ToValidate);
}

Expand Down Expand Up @@ -215,7 +222,7 @@ public void testcheckValidSSCC18_9digitManufacturerCode()
final SSCC18 sscc18ToValidate = new SSCC18(extensionDigit, manufacturerCode, serialNumber, checkDigit);
sscc18CodeBL.validate(sscc18ToValidate);

assertThat(sscc18CodeBL.toString(sscc18ToValidate, false)).hasSize(18).isEqualTo("0" + manufacturerCode + serialNumber + checkDigit);
assertThat(sscc18ToValidate.asString()).hasSize(18).isEqualTo("0" + manufacturerCode + serialNumber + checkDigit);
}

@Test(expected = AdempiereException.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private P060 createP060(

p060.setPartner(xmlDesadv.getCBPartnerID().getEdiRecipientGLN());

final String sscc18Value = Util.removePrecedingZeros(pack == null ? "" : pack.getIPASSCC18());
final String sscc18Value = pack == null ? "" : pack.getIPASSCC18();
p060.setNormalSSCC(sscc18Value);
p060.setGrainNummer(pack.getGTINLUPackingMaterial());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private void mapPackaging(
packIn.getPPACK1().add(ppack1);

final String sscc18 = validateString(
Util.removePrecedingZeros(lineAndPack.getPack().getIPASSCC18()),
lineAndPack.getPack().getIPASSCC18(),
"@FillMandatory@ SSCC in @EDI_DesadvLine_ID@ " + lineAndPack.getLine().getLine());
ppack1.setIDENTIFICATIONCODE(Util.lpadZero(sscc18, 18)/* if ssccRequired and we got here, then this is not null */);
ppack1.setIDENTIFICATIONQUAL(PackIdentificationQual.SSCC.toString());
Expand Down

0 comments on commit e7ef903

Please sign in to comment.