diff --git a/plugins/pipo/src/org/adempiere/pipo2/PoExporter.java b/plugins/pipo/src/org/adempiere/pipo2/PoExporter.java index 467bd77018..2af7887451 100644 --- a/plugins/pipo/src/org/adempiere/pipo2/PoExporter.java +++ b/plugins/pipo/src/org/adempiere/pipo2/PoExporter.java @@ -7,6 +7,8 @@ import java.util.Properties; import javax.xml.transform.sax.TransformerHandler; import org.adempiere.exceptions.AdempiereException; +import org.compiere.model.I_AD_Client; +import org.compiere.model.I_AD_Org; import org.compiere.model.MTable; import org.compiere.model.PO; import org.compiere.model.POInfo; @@ -190,8 +192,10 @@ public class PoExporter { { if (!preservedOrg) addString("AD_Org_ID", "@AD_Org_ID@", new AttributesImpl()); - else - addTableReference("AD_Org", "Value", new AttributesImpl()); + else { + addTableReference(I_AD_Client.Table_Name, I_AD_Client.COLUMNNAME_Value, new AttributesImpl()); + addTableReference(I_AD_Org.Table_Name, I_AD_Org.COLUMNNAME_Value, new AttributesImpl()); + } } } diff --git a/plugins/pipo/src/org/adempiere/pipo2/PoFiller.java b/plugins/pipo/src/org/adempiere/pipo2/PoFiller.java index 07bcb21bf7..4f3851739a 100644 --- a/plugins/pipo/src/org/adempiere/pipo2/PoFiller.java +++ b/plugins/pipo/src/org/adempiere/pipo2/PoFiller.java @@ -138,54 +138,26 @@ public class PoFiller{ Element e = element.properties.get(qName); if (e == null) return 0; - + String value = e.contents.toString(); - String reference = e.attributes.getValue("reference"); - String referenceKey = e.attributes.getValue("reference-key"); String columnName = qName; - if (value != null && value.trim().length() > 0) - { - if ("table".equals(reference)) - { - String[] names = referenceKey.split("[.]"); - if (names.length < 2) - return 0; - if (po.get_ColumnIndex(columnName) >= 0) { - String tableName = names[0]; - String searchColumn = names[1]; - - int id = handler.findIdByColumn(po.getCtx(), tableName, searchColumn, value.trim()); - if (id > 0) { - po.set_ValueOfColumn(columnName, id); - return id; - } + if (value != null && value.trim().length() > 0) { + int id = ReferenceUtils.resolveReference(ctx, e); + if (columnName.equals("AD_Client_ID") && id > 0) { + if (id != Env.getAD_Client_ID(ctx)) { return -1; - } else { - return 0; } } - else if ("id".equals(reference)) - { - int id = Integer.parseInt(value); - po.set_ValueOfColumn(e.getElementValue(), id); - return id; - } - else if ("uuid".equals(reference)) - { - int id = handler.findIdByColumn(po.getCtx(), referenceKey, referenceKey + "_UU", value.trim()); + if (po.get_ColumnIndex(columnName) >= 0) { if (id > 0) { po.set_ValueOfColumn(columnName, id); return id; } - return -1; + return -1; + } else { + return 0; } - else - { - throw new IllegalArgumentException("Unknown table reference type="+reference); - } - } - else - { + } else { return 0; } } @@ -205,8 +177,10 @@ public class PoFiller{ po.setAD_Org_ID(0); else if (sAD_Org_ID != null && sAD_Org_ID.equals("@AD_Org_ID@")) po.setAD_Org_ID(Env.getAD_Org_ID(ctx)); - else - setTableReference("AD_Org.Value"); + else { + if (setTableReference("AD_Client_ID") >= 0) + setTableReference("AD_Org_ID"); + } for(String qName : element.properties.keySet()) { if (excludes != null ){ diff --git a/plugins/pipo/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java b/plugins/pipo/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java index 7b7fce0d2d..6e21414494 100644 --- a/plugins/pipo/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java +++ b/plugins/pipo/src/org/adempiere/pipo2/handler/GenericPOElementHandler.java @@ -110,6 +110,18 @@ public class GenericPOElementHandler extends AbstractElementHandler implements I } PoFiller filler = new PoFiller(ctx, po, element, this); List excludes = defaultExcludeList(tableName); + if (po.get_ID() == 0) { + Element idElement = element.properties.get(tableName + "_ID"); + if (idElement != null && idElement.contents != null && idElement.contents.length() > 0) { + int id = 0; + try { + id = Integer.parseInt(idElement.contents.toString()); + if (id > 0 && id <= PackOut.MAX_OFFICIAL_ID) { + po.set_ValueOfColumn(tableName + "_ID", id); + } + } catch (Exception e) {} + } + } List notfounds = filler.autoFill(excludes); if (notfounds.size() > 0) { element.defer = true;