Skip to content

Commit

Permalink
Se agrega atributo para determinar si una orden de venta, factura, pago,
Browse files Browse the repository at this point in the history
cobro, orden de compra o documento por pagar es excento para retener en
función del tipo de documento
  • Loading branch information
yamelsenih committed Sep 10, 2022
1 parent 1487b3b commit c039bdb
Show file tree
Hide file tree
Showing 3 changed files with 743 additions and 3 deletions.
16 changes: 13 additions & 3 deletions core/src/main/java/base/org/erpya/lve/model/LVE.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.compiere.model.MMovement;
import org.compiere.model.MOrder;
import org.compiere.model.MOrderLine;
import org.compiere.model.MPayment;
import org.compiere.model.MTax;
import org.compiere.model.ModelValidationEngine;
import org.compiere.model.ModelValidator;
Expand Down Expand Up @@ -92,6 +93,8 @@ public void initialize(ModelValidationEngine engine, MClient client) {
engine.addModelChange(MBPartner.Table_Name, this);
engine.addModelChange(MWHWithholding.Table_Name, this);
engine.addModelChange(MInvoiceLine.Table_Name, this);
engine.addModelChange(MOrder.Table_Name, this);
engine.addModelChange(MPayment.Table_Name, this);

LVEImport importValidator = new LVEImport();
engine.addImportValidate(I_I_Invoice.Table_Name,importValidator);
Expand Down Expand Up @@ -400,7 +403,9 @@ public String modelChange(PO po, int type) throws Exception {
invoice.set_ValueOfColumn(LVEUtil.COLUMNNAME_WHThirdParty_ID, WHThirdParty_ID);
}
}
}if (po.get_TableName().equals(MInvoiceLine.Table_Name)) {
// By Default
LVEUtil.setDefaultValuesFromDocumentType(invoice);
} if (po.get_TableName().equals(MInvoiceLine.Table_Name)) {
MInvoiceLine invoiceLine = (MInvoiceLine) po;
MInvoice invoice = invoiceLine.getParent();
if (invoice.get_ValueAsInt(LVEUtil.COLUMNNAME_InvoiceToAllocate_ID)!= 0
Expand All @@ -413,8 +418,7 @@ else if(invoiceLine.is_ValueChanged(LVEUtil.COLUMNNAME_InvoiceToAllocate_ID)
invoice.set_ValueOfColumn(LVEUtil.COLUMNNAME_InvoiceToAllocate_ID, invoiceLine.get_ValueAsInt(LVEUtil.COLUMNNAME_InvoiceToAllocate_ID));
invoice.save();
}
}
else if(po.get_TableName().equals(MBPartner.Table_Name)) {
} else if(po.get_TableName().equals(MBPartner.Table_Name)) {
MBPartner businessPartner = (MBPartner) po;
if(type == TYPE_BEFORE_NEW
|| type == TYPE_BEFORE_CHANGE) {
Expand Down Expand Up @@ -445,6 +449,12 @@ else if(po.get_TableName().equals(MBPartner.Table_Name)) {
invoiceLine.set_ValueOfColumn("InvoiceToAllocate_ID", withholding.getSourceInvoice_ID());
invoiceLine.save();
}
} if (po.get_TableName().equals(MOrder.Table_Name)) {
// By Default
LVEUtil.setDefaultValuesFromDocumentType(po);
} if (po.get_TableName().equals(MPayment.Table_Name)) {
// By Default
LVEUtil.setDefaultValuesFromDocumentType(po);
}
} else if (type == TYPE_AFTER_CHANGE) {
// Set Is Paid for Auto Allocation Invoice Documents
Expand Down
29 changes: 29 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 @@ -23,7 +23,10 @@
import java.util.regex.Pattern;

import org.adempiere.exceptions.AdempiereException;
import org.compiere.model.I_C_Order;
import org.compiere.model.MDocType;
import org.compiere.model.MSysConfig;
import org.compiere.model.PO;
import org.compiere.util.Util;

/**
Expand Down Expand Up @@ -152,4 +155,30 @@ public static String processBusinessPartnerValue(Properties context, int clientI
.replaceAll("[^0-9JVEGjveg]", "")
.toUpperCase();
}

/**
* Set default values from document type
* @param entity
*/
public static void setDefaultValuesFromDocumentType(PO entity) {
int columnIndex = entity.get_ColumnIndex(I_C_Order.COLUMNNAME_C_DocTypeTarget_ID);
if(columnIndex < 0) {
columnIndex = entity.get_ColumnIndex(I_C_Order.COLUMNNAME_C_DocType_ID);
}
// Nothing
if(columnIndex < 0) {
return;
}
int documentTypeId = entity.get_ValueAsInt(columnIndex);
// No has a Document Type selected
if(documentTypeId <= 0) {
return;
}
if(entity.is_new()
|| entity.is_ValueChanged(columnIndex)) {
MDocType documentType = MDocType.get(entity.getCtx(), documentTypeId);
entity.set_ValueOfColumn(COLUMNNAME_IsWithholdingTaxExempt, documentType.get_Value(COLUMNNAME_IsWithholdingTaxExempt));
// Add here other columns from document type
}
}
}
Loading

0 comments on commit c039bdb

Please sign in to comment.