From ae955b6ee9bab54680c8b8a9b62523148d832d33 Mon Sep 17 00:00:00 2001 From: teo_sarca Date: Tue, 25 Aug 2009 07:17:43 +0000 Subject: [PATCH] FR [ 2844074 ] Requisition PO Create - more selection fields https://sourceforge.net/tracker/?func=detail&aid=2844074&group_id=176962&atid=879335 --- .../compiere/process/RequisitionPOCreate.java | 68 +++++++++++- ...844074_RequisitionPOCreate_more_fields.sql | 105 ++++++++++++++++++ ...844074_RequisitionPOCreate_more_fields.sql | 105 ++++++++++++++++++ 3 files changed, 273 insertions(+), 5 deletions(-) create mode 100644 migration/353a-trunk/oracle/540_FR2844074_RequisitionPOCreate_more_fields.sql create mode 100644 migration/353a-trunk/postgresql/540_FR2844074_RequisitionPOCreate_more_fields.sql diff --git a/base/src/org/compiere/process/RequisitionPOCreate.java b/base/src/org/compiere/process/RequisitionPOCreate.java index 0a824822e9..34a2c8ed2e 100644 --- a/base/src/org/compiere/process/RequisitionPOCreate.java +++ b/base/src/org/compiere/process/RequisitionPOCreate.java @@ -19,6 +19,7 @@ package org.compiere.process; import java.sql.Timestamp; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.logging.Level; import org.adempiere.exceptions.NoVendorForProductException; @@ -49,6 +50,8 @@ import org.compiere.util.Msg; *
  • BF [ 2605888 ] CreatePOfromRequisition creates more PO than needed *
  • BF [ 2811718 ] Create PO from Requsition without any parameter teminate in NPE * http://sourceforge.net/tracker/?func=detail&atid=879332&aid=2811718&group_id=176962 + *
  • FR [ 2844074 ] Requisition PO Create - more selection fields + * https://sourceforge.net/tracker/?func=detail&aid=2844074&group_id=176962&atid=879335 */ public class RequisitionPOCreate extends SvrProcess { @@ -70,6 +73,10 @@ public class RequisitionPOCreate extends SvrProcess private int p_AD_User_ID = 0; /** Product */ private int p_M_Product_ID = 0; + /** Product Category */ + private int p_M_Product_Category_ID = 0; + /** BPartner Group */ + private int p_C_BP_Group_ID = 0; /** Requisition */ private int p_M_Requisition_ID = 0; @@ -114,6 +121,10 @@ public class RequisitionPOCreate extends SvrProcess p_AD_User_ID = para[i].getParameterAsInt(); else if (name.equals("M_Product_ID")) p_M_Product_ID = para[i].getParameterAsInt(); + else if (name.equals("M_Product_Category_ID")) + p_M_Product_Category_ID = para[i].getParameterAsInt(); + else if (name.equals("C_BP_Group_ID")) + p_C_BP_Group_ID = para[i].getParameterAsInt(); else if (name.equals("M_Requisition_ID")) p_M_Requisition_ID = para[i].getParameterAsInt(); else if (name.equals("ConsolidateDocument")) @@ -163,21 +174,38 @@ public class RequisitionPOCreate extends SvrProcess ArrayList params = new ArrayList(); StringBuffer whereClause = new StringBuffer("C_OrderLine_ID IS NULL"); - if (p_AD_Org_ID != 0) + if (p_AD_Org_ID > 0) { whereClause.append(" AND AD_Org_ID=?"); params.add(p_AD_Org_ID); } - if (p_M_Product_ID != 0) + if (p_M_Product_ID > 0) { whereClause.append(" AND M_Product_ID=?"); params.add(p_M_Product_ID); } + else if (p_M_Product_Category_ID > 0) + { + whereClause.append(" AND EXISTS (SELECT 1 FROM M_Product p WHERE M_RequisitionLine.M_Product_ID=p.M_Product_ID") + .append(" AND p.M_Product_Category_ID=?)"); + params.add(p_M_Product_Category_ID); + } + + if (p_C_BP_Group_ID > 0) + { + whereClause.append(" AND (") + .append("M_RequisitionLine.C_BPartner_ID IS NULL") + .append(" OR EXISTS (SELECT 1 FROM C_BPartner bp WHERE M_RequisitionLine.C_BPartner_ID=bp.C_BPartner_ID AND bp.C_BP_Group_ID=?)") + .append(")"); + params.add(p_C_BP_Group_ID); + } + // // Requisition Header whereClause.append(" AND EXISTS (SELECT 1 FROM M_Requisition r WHERE M_RequisitionLine.M_Requisition_ID=r.M_Requisition_ID") - .append(" AND r.DocStatus='CO'"); - if (p_M_Warehouse_ID != 0) + .append(" AND r.DocStatus=?"); + params.add(MRequisition.DOCSTATUS_Completed); + if (p_M_Warehouse_ID > 0) { whereClause.append(" AND r.M_Warehouse_ID=?"); params.add(p_M_Warehouse_ID); @@ -207,7 +235,7 @@ public class RequisitionPOCreate extends SvrProcess whereClause.append(" AND r.PriorityRule => ?"); params.add(p_PriorityRule); } - if (p_AD_User_ID != 0) + if (p_AD_User_ID > 0) { whereClause.append(" AND r.AD_User_ID=?"); params.add(p_AD_User_ID); @@ -277,6 +305,9 @@ public class RequisitionPOCreate extends SvrProcess ) { newLine(rLine); + // No Order Line was produced (vendor was not valid/allowed) => SKIP + if (m_orderLine == null) + return; } // Update Order Line @@ -405,6 +436,12 @@ public class RequisitionPOCreate extends SvrProcess throw new NoVendorForProductException(product.getName()); } } + + if (!isGenerateForVendor(C_BPartner_ID)) + { + log.info("Skip for partner "+C_BPartner_ID); + return; + } // New Order - Different Vendor if (m_order == null @@ -436,5 +473,26 @@ public class RequisitionPOCreate extends SvrProcess m_M_AttributeSetInstance_ID = rLine.getM_AttributeSetInstance_ID(); m_orderLine.saveEx(); } // newLine + + /** + * Do we need to generate Purchase Orders for given Vendor + * @param C_BPartner_ID + * @return true if it's allowed + */ + private boolean isGenerateForVendor(int C_BPartner_ID) + { + if (p_C_BP_Group_ID <= 0 && m_excludedVendors.contains(C_BPartner_ID)) + return false; + // + boolean match = new Query(getCtx(), MBPartner.Table_Name, "C_BPartner_ID=? AND C_BP_Group_ID=?", get_TrxName()) + .setParameters(new Object[]{C_BPartner_ID, p_C_BP_Group_ID}) + .match(); + if (!match) + { + m_excludedVendors.add(C_BPartner_ID); + } + return match; + } + private List m_excludedVendors = new ArrayList(); } // RequisitionPOCreate diff --git a/migration/353a-trunk/oracle/540_FR2844074_RequisitionPOCreate_more_fields.sql b/migration/353a-trunk/oracle/540_FR2844074_RequisitionPOCreate_more_fields.sql new file mode 100644 index 0000000000..478185f633 --- /dev/null +++ b/migration/353a-trunk/oracle/540_FR2844074_RequisitionPOCreate_more_fields.sql @@ -0,0 +1,105 @@ +-- 21.08.2009 12:43:06 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,Updated,IsActive,Created,UpdatedBy,AD_Org_ID,CreatedBy,FieldLength,Name,IsCentrallyMaintained,IsRange,Description,Help,AD_Process_ID,EntityType,ColumnName,IsMandatory,SeqNo,AD_Reference_ID,AD_Element_ID) VALUES (53322,0,TO_DATE('2009-08-21 12:43:05','YYYY-MM-DD HH24:MI:SS'),'Y',TO_DATE('2009-08-21 12:43:05','YYYY-MM-DD HH24:MI:SS'),0,0,0,10,'Product Category','Y','N','Category of a Product','Identifies the category which this product belongs to. Product categories are used for pricing and selection.',337,'D','M_Product_Category_ID','N',90,19,453) +; + +-- 21.08.2009 12:43:07 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Name,Description,Help, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Name,t.Description,t.Help, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53322 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID) +; + +-- 21.08.2009 12:55:57 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,Updated,IsActive,Created,UpdatedBy,AD_Org_ID,CreatedBy,FieldLength,Name,IsCentrallyMaintained,IsRange,Description,Help,AD_Process_ID,EntityType,ColumnName,IsMandatory,SeqNo,AD_Reference_ID,AD_Element_ID) VALUES (53323,0,TO_DATE('2009-08-21 12:55:55','YYYY-MM-DD HH24:MI:SS'),'Y',TO_DATE('2009-08-21 12:55:55','YYYY-MM-DD HH24:MI:SS'),0,0,0,10,'Business Partner Group','Y','N','Business Partner Group','The Business Partner Group provides a method of defining defaults to be used for individual Business Partners.',337,'D','C_BP_Group_ID','N',100,30,1383) +; + +-- 21.08.2009 12:55:57 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Name,Description,Help, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Name,t.Description,t.Help, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53323 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID) +; + +-- 21.08.2009 12:56:22 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=10,IsActive='Y' WHERE AD_Process_Para_ID=697 +; + +-- 21.08.2009 12:56:22 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=20,IsActive='Y' WHERE AD_Process_Para_ID=689 +; + +-- 21.08.2009 12:56:22 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=30,IsActive='Y' WHERE AD_Process_Para_ID=690 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=40,IsActive='Y' WHERE AD_Process_Para_ID=688 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=50,IsActive='Y' WHERE AD_Process_Para_ID=691 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=60,IsActive='Y' WHERE AD_Process_Para_ID=692 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=70,IsActive='Y' WHERE AD_Process_Para_ID=693 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=80,IsActive='Y' WHERE AD_Process_Para_ID=695 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=110,IsActive='Y' WHERE AD_Process_Para_ID=694 +; + +-- 21.08.2009 12:56:37 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='Y',Updated=TO_DATE('2009-08-21 12:56:37','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=694 +; + +-- 21.08.2009 12:56:44 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET IsMandatory='Y',Updated=TO_DATE('2009-08-21 12:56:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=694 +; + +-- 21.08.2009 12:57:04 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DisplayLogic='@M_Product_ID@=0',Updated=TO_DATE('2009-08-21 12:57:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53322 +; + +-- 21.08.2009 12:57:13 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DisplayLogic='@M_Product_Category_ID@=0',Updated=TO_DATE('2009-08-21 12:57:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=695 +; + +-- 21.08.2009 12:57:50 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='-1',Updated=TO_DATE('2009-08-21 12:57:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=695 +; + +-- 21.08.2009 12:57:53 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='-1',Updated=TO_DATE('2009-08-21 12:57:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53322 +; + +-- 21.08.2009 12:57:59 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='-1',Updated=TO_DATE('2009-08-21 12:57:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53323 +; + +-- 21.08.2009 12:58:16 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET AD_Reference_ID=19,Updated=TO_DATE('2009-08-21 12:58:16','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53323 +; + diff --git a/migration/353a-trunk/postgresql/540_FR2844074_RequisitionPOCreate_more_fields.sql b/migration/353a-trunk/postgresql/540_FR2844074_RequisitionPOCreate_more_fields.sql new file mode 100644 index 0000000000..a8c7138b08 --- /dev/null +++ b/migration/353a-trunk/postgresql/540_FR2844074_RequisitionPOCreate_more_fields.sql @@ -0,0 +1,105 @@ +-- 21.08.2009 12:43:06 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,Updated,IsActive,Created,UpdatedBy,AD_Org_ID,CreatedBy,FieldLength,Name,IsCentrallyMaintained,IsRange,Description,Help,AD_Process_ID,EntityType,ColumnName,IsMandatory,SeqNo,AD_Reference_ID,AD_Element_ID) VALUES (53322,0,TO_TIMESTAMP('2009-08-21 12:43:05','YYYY-MM-DD HH24:MI:SS'),'Y',TO_TIMESTAMP('2009-08-21 12:43:05','YYYY-MM-DD HH24:MI:SS'),0,0,0,10,'Product Category','Y','N','Category of a Product','Identifies the category which this product belongs to. Product categories are used for pricing and selection.',337,'D','M_Product_Category_ID','N',90,19,453) +; + +-- 21.08.2009 12:43:07 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Name,Description,Help, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Name,t.Description,t.Help, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53322 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID) +; + +-- 21.08.2009 12:55:57 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para (AD_Process_Para_ID,AD_Client_ID,Updated,IsActive,Created,UpdatedBy,AD_Org_ID,CreatedBy,FieldLength,Name,IsCentrallyMaintained,IsRange,Description,Help,AD_Process_ID,EntityType,ColumnName,IsMandatory,SeqNo,AD_Reference_ID,AD_Element_ID) VALUES (53323,0,TO_TIMESTAMP('2009-08-21 12:55:55','YYYY-MM-DD HH24:MI:SS'),'Y',TO_TIMESTAMP('2009-08-21 12:55:55','YYYY-MM-DD HH24:MI:SS'),0,0,0,10,'Business Partner Group','Y','N','Business Partner Group','The Business Partner Group provides a method of defining defaults to be used for individual Business Partners.',337,'D','C_BP_Group_ID','N',100,30,1383) +; + +-- 21.08.2009 12:55:57 EEST +-- Requisition PO Create - more selection fields +INSERT INTO AD_Process_Para_Trl (AD_Language,AD_Process_Para_ID, Name,Description,Help, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Process_Para_ID, t.Name,t.Description,t.Help, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Process_Para t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Process_Para_ID=53323 AND EXISTS (SELECT * FROM AD_Process_Para_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Process_Para_ID!=t.AD_Process_Para_ID) +; + +-- 21.08.2009 12:56:22 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=10,IsActive='Y' WHERE AD_Process_Para_ID=697 +; + +-- 21.08.2009 12:56:22 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=20,IsActive='Y' WHERE AD_Process_Para_ID=689 +; + +-- 21.08.2009 12:56:22 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=30,IsActive='Y' WHERE AD_Process_Para_ID=690 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=40,IsActive='Y' WHERE AD_Process_Para_ID=688 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=50,IsActive='Y' WHERE AD_Process_Para_ID=691 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=60,IsActive='Y' WHERE AD_Process_Para_ID=692 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=70,IsActive='Y' WHERE AD_Process_Para_ID=693 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=80,IsActive='Y' WHERE AD_Process_Para_ID=695 +; + +-- 21.08.2009 12:56:23 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET SeqNo=110,IsActive='Y' WHERE AD_Process_Para_ID=694 +; + +-- 21.08.2009 12:56:37 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='Y',Updated=TO_TIMESTAMP('2009-08-21 12:56:37','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=694 +; + +-- 21.08.2009 12:56:44 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET IsMandatory='Y',Updated=TO_TIMESTAMP('2009-08-21 12:56:44','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=694 +; + +-- 21.08.2009 12:57:04 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DisplayLogic='@M_Product_ID@=0',Updated=TO_TIMESTAMP('2009-08-21 12:57:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53322 +; + +-- 21.08.2009 12:57:13 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DisplayLogic='@M_Product_Category_ID@=0',Updated=TO_TIMESTAMP('2009-08-21 12:57:13','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=695 +; + +-- 21.08.2009 12:57:50 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='-1',Updated=TO_TIMESTAMP('2009-08-21 12:57:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=695 +; + +-- 21.08.2009 12:57:53 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='-1',Updated=TO_TIMESTAMP('2009-08-21 12:57:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53322 +; + +-- 21.08.2009 12:57:59 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET DefaultValue='-1',Updated=TO_TIMESTAMP('2009-08-21 12:57:59','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53323 +; + +-- 21.08.2009 12:58:16 EEST +-- Requisition PO Create - more selection fields +UPDATE AD_Process_Para SET AD_Reference_ID=19,Updated=TO_TIMESTAMP('2009-08-21 12:58:16','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Process_Para_ID=53323 +; +