From 6758daac61fc44c29f602538f65f81f8351ea84c Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 13 Aug 2014 15:06:08 +0800 Subject: [PATCH] IDEMPIERE-2144 Pack in of Attachment: Update entry is using wrong index. --- org.adempiere.base/src/org/compiere/model/MAttachment.java | 1 + .../src/org/compiere/model/MAttachmentEntry.java | 4 ++++ org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java | 7 ++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/model/MAttachment.java b/org.adempiere.base/src/org/compiere/model/MAttachment.java index 700e5f481a..8c73f28c87 100644 --- a/org.adempiere.base/src/org/compiere/model/MAttachment.java +++ b/org.adempiere.base/src/org/compiere/model/MAttachment.java @@ -303,6 +303,7 @@ public class MAttachment extends X_AD_Attachment } if (!replaced) { retValue = m_items.add(item); + item.setIndex(m_items.size()); } if (log.isLoggable(Level.FINE)) log.fine(item.toStringX()); setBinaryData(new byte[0]); // ATTENTION! HEAVY HACK HERE... Else it will not save :( diff --git a/org.adempiere.base/src/org/compiere/model/MAttachmentEntry.java b/org.adempiere.base/src/org/compiere/model/MAttachmentEntry.java index c3dc3d371c..4a6af5e325 100644 --- a/org.adempiere.base/src/org/compiere/model/MAttachmentEntry.java +++ b/org.adempiere.base/src/org/compiere/model/MAttachmentEntry.java @@ -295,5 +295,9 @@ public class MAttachmentEntry return null; return new ByteArrayInputStream(m_data); } // getInputStream + + public void setIndex(int index) { + m_index = index; + } } // MAttachmentItem diff --git a/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java b/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java index 73ce8778d0..f69f718da3 100644 --- a/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java +++ b/org.adempiere.pipo/src/org/adempiere/pipo2/PoFiller.java @@ -304,15 +304,20 @@ public class PoFiller{ MAttachment attach = ((MAttachment)po); for (File file : files) { boolean found = false; + int index = -1; for (MAttachmentEntry entry : attach.getEntries()) { + index++; if (entry.getName().equals(file.getName())) { found = true; - attach.updateEntry(entry.getIndex(), file); + attach.updateEntry(index, file); + break; } } if (! found) attach.addEntry(file); } + if (!attach.is_Changed()) + attach.set_ValueNoCheck("Updated", new Timestamp(System.currentTimeMillis())); } } else { Object data = null;