Skip to content

Commit

Permalink
Fixes: #60
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Apr 30, 2024
1 parent 76c07d4 commit 2708921
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 9 additions & 2 deletions core/src/main/java/base/org/erpya/lve/model/LVE.java
Original file line number Diff line number Diff line change
Expand Up @@ -424,14 +424,21 @@ else if(invoiceLine.is_ValueChanged(LVEUtil.COLUMNNAME_InvoiceToAllocate_ID)
// Validate without values
if(businessPartner.is_ValueChanged(I_C_BPartner.COLUMNNAME_Value)) {
String value = LVEUtil.processBusinessPartnerValue(businessPartner.getCtx(), businessPartner.getAD_Client_ID(), businessPartner.getAD_Org_ID(), businessPartner.getValue());
String taxId = LVEUtil.processBusinessPartnerValue(businessPartner.getCtx(), businessPartner.getAD_Client_ID(), businessPartner.getAD_Org_ID(), businessPartner.getTaxID());
String taxId = LVEUtil.getValidTaxId(businessPartner.getCtx(), businessPartner.getAD_Client_ID(), businessPartner.getAD_Org_ID(), businessPartner.getTaxID());
if(value.charAt(0) != taxId.charAt(0)) {
throw new AdempiereException("@" + LVEUtil.MESSAGE_LVE_ValueTaxIdMismatch + "@");
}
businessPartner.setValue(value);
// For Tax ID
if(Util.isEmpty(taxId)) {
businessPartner.setTaxID(value);
}
} else if(businessPartner.is_ValueChanged(I_C_BPartner.COLUMNNAME_TaxID)) {
String taxId = LVEUtil.processBusinessPartnerValue(businessPartner.getCtx(), businessPartner.getAD_Client_ID(), businessPartner.getAD_Org_ID(), businessPartner.getTaxID());
String value = LVEUtil.processBusinessPartnerValue(businessPartner.getCtx(), businessPartner.getAD_Client_ID(), businessPartner.getAD_Org_ID(), businessPartner.getValue());
String taxId = LVEUtil.getValidTaxId(businessPartner.getCtx(), businessPartner.getAD_Client_ID(), businessPartner.getAD_Org_ID(), businessPartner.getTaxID());
if(value.charAt(0) != taxId.charAt(0)) {
throw new AdempiereException("@" + LVEUtil.MESSAGE_LVE_ValueTaxIdMismatch + "@");
}
businessPartner.setTaxID(taxId);
}
if(type == TYPE_BEFORE_NEW) {
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/base/org/erpya/lve/util/LVEUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public class LVEUtil {
public static final String COLUMNNAME_LVE_AllowOverPayInvoice = "LVE_AllowOverPayInvoice";
/** Allows overwrite document */
public static final String LVE_AllowOverdraftReference = "LVE_AllowOverdraftReference";
/** Value and Tax ID Mismatch */
public static final String MESSAGE_LVE_ValueTaxIdMismatch = "LVE.ValueTaxIdMismatch";
/**
* Process Business Partner Value
* @param value
Expand Down Expand Up @@ -164,6 +166,21 @@ public static String processBusinessPartnerValue(Properties context, int clientI
.toUpperCase();
}

/**
* Get Valid Tax ID
* @param context
* @param clientId
* @param organizationId
* @param value
* @return
*/
public static String getValidTaxId(Properties context, int clientId, int organizationId, String value) {
String taxId = processBusinessPartnerValue(context, clientId, organizationId, value);
String taxIdOnlyNumbers = taxId.replaceAll("\\D+","");
taxIdOnlyNumbers = String.format("%1$" + 9 + "s", taxIdOnlyNumbers).replace(" ", "0");
return taxId.substring(0, 1) + taxIdOnlyNumbers;
}

/**
* Set default values from document type
* @param entity
Expand Down

0 comments on commit 2708921

Please sign in to comment.