Skip to content

Commit

Permalink
Se corrige evento para cálculo de retención de IVA y posible duplicidad
Browse files Browse the repository at this point in the history
de comprobante
  • Loading branch information
yamelsenih committed Sep 5, 2022
1 parent 221835c commit 26ace12
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ private void setupWithholding() {
maxSequence += 10;
}
// Order New
if(createSettingWithEvent(withHolgingType.getWH_Type_ID(), org.erpya.lve.util.POSOrderIVANew.class.getName(), MWHSetting.EVENTMODELVALIDATOR_TableBeforeNew, I_C_Order.Table_ID, "IVA-Orden-Crear", "Retención I.V.A Antes de Crear Orden de Venta", maxSequence)) {
if(createSettingWithEvent(withHolgingType.getWH_Type_ID(), org.erpya.lve.util.POSOrderIVANew.class.getName(), MWHSetting.EVENTMODELVALIDATOR_TableAfterNew, I_C_Order.Table_ID, "IVA-Orden-Crear", "Retención I.V.A Antes de Crear Orden de Venta", maxSequence)) {
maxSequence += 10;
}
// Order Change
if(createSettingWithEvent(withHolgingType.getWH_Type_ID(), org.erpya.lve.util.POSOrderIVAChange.class.getName(), MWHSetting.EVENTMODELVALIDATOR_TableBeforeChange, I_C_Order.Table_ID, "IVA-Orden-Modificar", "Retención I.V.A Antes de odificar Orden de Venta", maxSequence)) {
if(createSettingWithEvent(withHolgingType.getWH_Type_ID(), org.erpya.lve.util.POSOrderIVAChange.class.getName(), MWHSetting.EVENTMODELVALIDATOR_TableAfterChange, I_C_Order.Table_ID, "IVA-Orden-Modificar", "Retención I.V.A Antes de odificar Orden de Venta", maxSequence)) {
maxSequence += 10;
}
// Order Process
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,39 @@ public boolean isValid() {
// Validate Document
if(getDocument().get_Table_ID() != I_C_OrderLine.Table_ID
&& getDocument().get_Table_ID() != I_C_Order.Table_ID) {
addLog("@C_Order_ID@ @NotFound@");
isValid = false;
return false;
}
String event = getSetting().getEventModelValidator();
if(Util.isEmpty(event)) {
return false;
}
if(getDocument().get_Table_ID() == I_C_OrderLine.Table_ID) {
if(!(getDocument().is_ValueChanged("LineNetAmt")
|| getDocument().is_ValueChanged("C_Tax_ID"))
&& !event.equals(MWHSetting.EVENTMODELVALIDATOR_TableAfterNew)) {
return false;
}
MOrderLine orderLine = (MOrderLine) getDocument();
order = orderLine.getParent();
} else {
if(!(getDocument().is_ValueChanged("C_DocTypeTarget_ID")
|| getDocument().is_ValueChanged("C_BPartner_ID"))) {
return false;
}
order = (MOrder) getDocument();
}
if(order.getC_POS_ID() <= 0) {
return false;
}
businessPartner = (MBPartner) order.getC_BPartner();
// Validate Processed
if(order.isProcessed()) {
return false;
}
if(!businessPartner.get_ValueAsBoolean(LVEUtil.COLUMNNAME_IsTaxpayer)) {
deleteReference();
return false;
}
if(order.getC_POS_ID() <= 0) {
addLog("@C_POS_ID@ @NotFound@");
isValid = false;
}
//Valid Business Partner
Optional.ofNullable(order)
.ifPresent(order ->{
Expand Down Expand Up @@ -257,7 +269,8 @@ protected void savePaymentReference(boolean createIfNotExists) {
PO paymentReferenceToCreate = new Query(getContext(), "C_POSPaymentReference",
"C_Order_ID = ? "
+ "AND TenderType = ? "
+ "AND C_PaymentMethod_ID = ?", getTransactionName())
+ "AND C_PaymentMethod_ID = ? "
+ "AND Processed = 'N'", getTransactionName())
.setClient_ID()
.setParameters(order.getC_Order_ID(), MPayment.TENDERTYPE_CreditMemo, getDefaultPaymentMethodAllocated().get_ValueAsInt("C_PaymentMethod_ID")).first();
// Create
Expand Down Expand Up @@ -296,17 +309,24 @@ protected void savePaymentReference(boolean createIfNotExists) {
setWithholdingAmount(Env.ZERO);
setDefaultPaymentMethodAllocated(null);
} else {
MTable paymentReferenceDefinition = MTable.get(getContext(), "C_POSPaymentReference");
if(paymentReferenceDefinition != null) {
PO paymentReferenceToDelete = new Query(getContext(), "C_POSPaymentReference",
"C_Order_ID = ? "
+ "AND TenderType = ? "
+ "AND C_PaymentMethod_ID = ?", getTransactionName())
.setClient_ID()
.setParameters(order.getC_Order_ID(), MPayment.TENDERTYPE_CreditMemo, getDefaultPaymentMethodAllocated().get_ValueAsInt("C_PaymentMethod_ID")).first();
if(paymentReferenceToDelete != null) {
paymentReferenceToDelete.deleteEx(true);
}
deleteReference();
}
}

/**
* Delete payment reference
*/
private void deleteReference() {
MTable paymentReferenceDefinition = MTable.get(getContext(), "C_POSPaymentReference");
if(paymentReferenceDefinition != null) {
PO paymentReferenceToDelete = new Query(getContext(), "C_POSPaymentReference",
"C_Order_ID = ? "
+ "AND TenderType = ? "
+ "AND C_PaymentMethod_ID = ?", getTransactionName())
.setClient_ID()
.setParameters(order.getC_Order_ID(), MPayment.TENDERTYPE_CreditMemo, getDefaultPaymentMethodAllocated().get_ValueAsInt("C_PaymentMethod_ID")).first();
if(paymentReferenceToDelete != null) {
paymentReferenceToDelete.deleteEx(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ private void fillReferences() {
"C_Order_ID = ? AND TenderType = ? "
+ "AND EXISTS(SELECT 1 FROM C_PaymentMethod pm "
+ "WHERE pm.C_PaymentMethod_ID = C_POSPaymentReference.C_PaymentMethod_ID "
+ "AND pm.IsWithholdingExempt = 'N' "
+ "AND pm.WH_Type_ID = ?)", getTransactionName())
.setParameters(order.getC_Order_ID(), MPayment.TENDERTYPE_CreditMemo, getSetting().getWH_Type_ID())
.getIDsAsList();
Expand All @@ -121,10 +120,10 @@ public String run() {
if(invoiceId > 0) {
setReturnValue(I_WH_Withholding.COLUMNNAME_SourceInvoice_ID, invoiceId);
}
paymentReference.set_ValueOfColumn("IsPaid", true);
paymentReference.set_ValueOfColumn("Processed", true);
paymentReference.saveEx();
saveResult();
paymentReferenceDefinition.set_ValueOfColumn("IsPaid", true);
paymentReferenceDefinition.set_ValueOfColumn("Processed", true);
paymentReferenceDefinition.saveEx();
});
}
return null;
Expand Down

0 comments on commit 26ace12

Please sign in to comment.