IDEMPIERE-918 Allow to choose the reversal document for invoice - Add C_Invoice.RelatedInvoice_ID

This commit is contained in:
Nicolas Micoud 2019-07-26 18:00:26 +02:00
parent cc881f7354
commit 33729acb64
5 changed files with 141 additions and 15 deletions

View File

@ -0,0 +1,46 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- IDEMPIERE-918 - add C_Invoice.RelatedInvoice_ID
-- 07/25/2019 11:08:54
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,PrintName,EntityType,AD_Element_UU) VALUES (203348,0,0,'Y',TO_DATE('2019-07-25 11:08:54','YYYY-MM-DD HH24:MI:SS'),0,TO_DATE('2019-07-25 11:08:54','YYYY-MM-DD HH24:MI:SS'),0,'RelatedInvoice_ID','Related Invoice','Related Invoice','D','30673d40-aeaa-4d46-b9aa-fd2d41ab90f8')
;
-- 07/25/2019 11:10:03
INSERT INTO AD_Column (AD_Column_ID,Version,Name,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Reference_Value_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (213967,0,'Related Invoice',318,'RelatedInvoice_ID',10,'N','N','N','N','N',0,'N',30,336,0,0,'Y',TO_DATE('2019-07-25 11:10:03','YYYY-MM-DD HH24:MI:SS'),0,TO_DATE('2019-07-25 11:10:03','YYYY-MM-DD HH24:MI:SS'),0,203348,'Y','N','D','N','N','N','Y','75158448-52e0-426b-a393-86141d86157e','N',0,'N','N','N','N')
;
-- 07/25/2019 11:10:08
UPDATE AD_Column SET FKConstraintName='RelatedInvoice_CInvoice', FKConstraintType='N',Updated=TO_DATE('2019-07-25 11:10:08','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=213967
;
-- 07/25/2019 11:10:08
ALTER TABLE C_Invoice ADD RelatedInvoice_ID NUMBER(10) DEFAULT NULL
;
-- 07/25/2019 11:10:08
ALTER TABLE C_Invoice ADD CONSTRAINT RelatedInvoice_CInvoice FOREIGN KEY (RelatedInvoice_ID) REFERENCES c_invoice(c_invoice_id) DEFERRABLE INITIALLY DEFERRED
;
-- 07/25/2019 11:10:35
INSERT INTO AD_Field (AD_Field_ID,Name,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206135,'Related Invoice',263,213967,'Y',10,460,'N','N','N','N',0,0,'Y',TO_DATE('2019-07-25 11:10:35','YYYY-MM-DD HH24:MI:SS'),0,TO_DATE('2019-07-25 11:10:35','YYYY-MM-DD HH24:MI:SS'),0,'N','Y','D','ecbcf980-4cfe-4937-b31a-9e18e7e5767e','Y',450,2)
;
-- 07/25/2019 11:10:44
UPDATE AD_Field SET SeqNo=0, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2019-07-25 11:10:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=204733
;
-- 07/25/2019 11:11:21
UPDATE AD_Field SET DisplayLogic='@RelatedInvoice_ID@ > 0', IsReadOnly='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2019-07-25 11:11:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=206135
;
-- 07/25/2019 11:11:38
INSERT INTO AD_Field (AD_Field_ID,Name,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206136,'Related Invoice',290,213967,'Y',10,440,'N','N','N','N',0,0,'Y',TO_DATE('2019-07-25 11:11:37','YYYY-MM-DD HH24:MI:SS'),0,TO_DATE('2019-07-25 11:11:37','YYYY-MM-DD HH24:MI:SS'),0,'N','Y','D','e0bb818f-dfc1-494c-a9c2-1d5f1a9c7945','Y',430,2)
;
-- 07/25/2019 11:12:06
UPDATE AD_Field SET DisplayLogic='@RelatedInvoice_ID@ > 0', IsReadOnly='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2019-07-25 11:12:06','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=206136
;
SELECT register_migration_script('201907251130_IDEMPIERE-918_Invoice_RelatedInvoice_ID.sql') FROM dual
;

View File

@ -0,0 +1,43 @@
-- IDEMPIERE-918 - add C_Invoice.RelatedInvoice_ID
-- 07/25/2019 11:08:54
INSERT INTO AD_Element (AD_Element_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,ColumnName,Name,PrintName,EntityType,AD_Element_UU) VALUES (203348,0,0,'Y',TO_TIMESTAMP('2019-07-25 11:08:54','YYYY-MM-DD HH24:MI:SS'),0,TO_TIMESTAMP('2019-07-25 11:08:54','YYYY-MM-DD HH24:MI:SS'),0,'RelatedInvoice_ID','Related Invoice','Related Invoice','D','30673d40-aeaa-4d46-b9aa-fd2d41ab90f8')
;
-- 07/25/2019 11:10:03
INSERT INTO AD_Column (AD_Column_ID,Version,Name,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Reference_Value_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,FKConstraintType,IsHtml) VALUES (213967,0,'Related Invoice',318,'RelatedInvoice_ID',10,'N','N','N','N','N',0,'N',30,336,0,0,'Y',TO_TIMESTAMP('2019-07-25 11:10:03','YYYY-MM-DD HH24:MI:SS'),0,TO_TIMESTAMP('2019-07-25 11:10:03','YYYY-MM-DD HH24:MI:SS'),0,203348,'Y','N','D','N','N','N','Y','75158448-52e0-426b-a393-86141d86157e','N',0,'N','N','N','N')
;
-- 07/25/2019 11:10:08
UPDATE AD_Column SET FKConstraintName='RelatedInvoice_CInvoice', FKConstraintType='N',Updated=TO_TIMESTAMP('2019-07-25 11:10:08','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Column_ID=213967
;
-- 07/25/2019 11:10:08
ALTER TABLE C_Invoice ADD COLUMN RelatedInvoice_ID NUMERIC(10) DEFAULT NULL
;
-- 07/25/2019 11:10:08
ALTER TABLE C_Invoice ADD CONSTRAINT RelatedInvoice_CInvoice FOREIGN KEY (RelatedInvoice_ID) REFERENCES c_invoice(c_invoice_id) DEFERRABLE INITIALLY DEFERRED
;
-- 07/25/2019 11:10:35
INSERT INTO AD_Field (AD_Field_ID,Name,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206135,'Related Invoice',263,213967,'Y',10,460,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2019-07-25 11:10:35','YYYY-MM-DD HH24:MI:SS'),0,TO_TIMESTAMP('2019-07-25 11:10:35','YYYY-MM-DD HH24:MI:SS'),0,'N','Y','D','ecbcf980-4cfe-4937-b31a-9e18e7e5767e','Y',450,2)
;
-- 07/25/2019 11:10:44
UPDATE AD_Field SET SeqNo=0, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2019-07-25 11:10:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=204733
;
-- 07/25/2019 11:11:21
UPDATE AD_Field SET DisplayLogic='@RelatedInvoice_ID@ > 0', IsReadOnly='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2019-07-25 11:11:21','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=206135
;
-- 07/25/2019 11:11:38
INSERT INTO AD_Field (AD_Field_ID,Name,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan) VALUES (206136,'Related Invoice',290,213967,'Y',10,440,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2019-07-25 11:11:37','YYYY-MM-DD HH24:MI:SS'),0,TO_TIMESTAMP('2019-07-25 11:11:37','YYYY-MM-DD HH24:MI:SS'),0,'N','Y','D','e0bb818f-dfc1-494c-a9c2-1d5f1a9c7945','Y',430,2)
;
-- 07/25/2019 11:12:06
UPDATE AD_Field SET DisplayLogic='@RelatedInvoice_ID@ > 0', IsReadOnly='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2019-07-25 11:12:06','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Field_ID=206136
;
SELECT register_migration_script('201907251130_IDEMPIERE-918_Invoice_RelatedInvoice_ID.sql') FROM dual
;

View File

@ -110,20 +110,14 @@ public class InvoiceCreateCreditMemo extends SvrProcess {
throw new AdempiereException(Msg.getMsg(getCtx(), "CannotCreateCreditMemoFromCreditMemo")); throw new AdempiereException(Msg.getMsg(getCtx(), "CannotCreateCreditMemoFromCreditMemo"));
} }
// Validate if there is already another credit memo for this invoice (via POReference) // Validate if there is already another credit memo for this invoice (via POReference)
final String sql = ""
+ "SELECT C_Invoice_ID " // TODO Carlos : 2 ways - using invoice own field or searching a credit memo
+ "FROM C_Invoice i " int id = 0;
+ " JOIN C_DocType dt ON ( i.C_DocType_ID = dt.C_DocType_ID ) " if (invoice.getRelatedInvoice_ID() > 0)
+ "WHERE i.POReference = ? " id = invoice.getRelatedInvoice_ID();
+ " AND dt.DocBaseType IN ( ?, ? ) "
+ " AND i.C_BPartner_ID = ? " id = DB.getSQLValueEx(get_TrxName(), "SELECT C_Invoice_ID FROM C_Invoice WHERE RelatedInvoice_ID = ?", invoice.getC_Invoice_ID());
+ " AND i.AD_Client_ID = ? "
+ " AND i.AD_Org_ID = ?";
int id = DB.getSQLValue(get_TrxName(), sql,
invoice.getDocumentNo(),
MDocType.DOCBASETYPE_APCreditMemo, MDocType.DOCBASETYPE_ARCreditMemo,
invoice.getC_BPartner_ID(),
invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
if (id > 0) { if (id > 0) {
MInvoice actualCreditMemo = MInvoice.get(getCtx(), id); MInvoice actualCreditMemo = MInvoice.get(getCtx(), id);
MDocType dtc = MDocType.get(getCtx(), actualCreditMemo.getC_DocTypeTarget_ID()); MDocType dtc = MDocType.get(getCtx(), actualCreditMemo.getC_DocTypeTarget_ID());
@ -133,6 +127,12 @@ public class InvoiceCreateCreditMemo extends SvrProcess {
MInvoice creditMemo = credit(); MInvoice creditMemo = credit();
if (creditMemo != null) { if (creditMemo != null) {
// TODO Carlos - remove those 2 lines it if you think it's not a good idea to fill the field for the invoice
invoice.setRelatedInvoice_ID(creditMemo.getC_Invoice_ID());
invoice.saveEx();
MDocType dtc = MDocType.get(getCtx(), creditMemo.getC_DocTypeTarget_ID()); MDocType dtc = MDocType.get(getCtx(), creditMemo.getC_DocTypeTarget_ID());
addLog(0, null, null, dtc.getName() + " " + creditMemo.getDocumentNo(), MInvoice.Table_ID, creditMemo.getC_Invoice_ID()); addLog(0, null, null, dtc.getName() + " " + creditMemo.getDocumentNo(), MInvoice.Table_ID, creditMemo.getC_Invoice_ID());
} }
@ -182,6 +182,7 @@ public class InvoiceCreateCreditMemo extends SvrProcess {
StringBuilder msgadd = new StringBuilder("{->").append(invoice.getDocumentNo()).append(")"); StringBuilder msgadd = new StringBuilder("{->").append(invoice.getDocumentNo()).append(")");
creditMemo.addDescription(msgadd.toString()); creditMemo.addDescription(msgadd.toString());
creditMemo.setPOReference(invoice.getDocumentNo()); creditMemo.setPOReference(invoice.getDocumentNo());
creditMemo.setRelatedInvoice_ID(invoice.getC_Invoice_ID());
creditMemo.saveEx(get_TrxName()); creditMemo.saveEx(get_TrxName());
// //
if (p_DocAction != null) { if (p_DocAction != null) {

View File

@ -816,6 +816,17 @@ public interface I_C_Invoice
/** Get Referenced Invoice */ /** Get Referenced Invoice */
public int getRef_Invoice_ID(); public int getRef_Invoice_ID();
/** Column name RelatedInvoice_ID */
public static final String COLUMNNAME_RelatedInvoice_ID = "RelatedInvoice_ID";
/** Set Related Invoice */
public void setRelatedInvoice_ID (int RelatedInvoice_ID);
/** Get Related Invoice */
public int getRelatedInvoice_ID();
public org.compiere.model.I_C_Invoice getRelatedInvoice() throws RuntimeException;
/** Column name Reversal_ID */ /** Column name Reversal_ID */
public static final String COLUMNNAME_Reversal_ID = "Reversal_ID"; public static final String COLUMNNAME_Reversal_ID = "Reversal_ID";

View File

@ -33,7 +33,7 @@ public class X_C_Invoice extends PO implements I_C_Invoice, I_Persistent
/** /**
* *
*/ */
private static final long serialVersionUID = 20190106L; private static final long serialVersionUID = 20190725L;
/** Standard Constructor */ /** Standard Constructor */
public X_C_Invoice (Properties ctx, int C_Invoice_ID, String trxName) public X_C_Invoice (Properties ctx, int C_Invoice_ID, String trxName)
@ -1454,6 +1454,31 @@ public class X_C_Invoice extends PO implements I_C_Invoice, I_Persistent
return ii.intValue(); return ii.intValue();
} }
public org.compiere.model.I_C_Invoice getRelatedInvoice() throws RuntimeException
{
return (org.compiere.model.I_C_Invoice)MTable.get(getCtx(), org.compiere.model.I_C_Invoice.Table_Name)
.getPO(getRelatedInvoice_ID(), get_TrxName()); }
/** Set Related Invoice.
@param RelatedInvoice_ID Related Invoice */
public void setRelatedInvoice_ID (int RelatedInvoice_ID)
{
if (RelatedInvoice_ID < 1)
set_Value (COLUMNNAME_RelatedInvoice_ID, null);
else
set_Value (COLUMNNAME_RelatedInvoice_ID, Integer.valueOf(RelatedInvoice_ID));
}
/** Get Related Invoice.
@return Related Invoice */
public int getRelatedInvoice_ID ()
{
Integer ii = (Integer)get_Value(COLUMNNAME_RelatedInvoice_ID);
if (ii == null)
return 0;
return ii.intValue();
}
public org.compiere.model.I_C_Invoice getReversal() throws RuntimeException public org.compiere.model.I_C_Invoice getReversal() throws RuntimeException
{ {
return (org.compiere.model.I_C_Invoice)MTable.get(getCtx(), org.compiere.model.I_C_Invoice.Table_Name) return (org.compiere.model.I_C_Invoice)MTable.get(getCtx(), org.compiere.model.I_C_Invoice.Table_Name)