Fixes issue 0021809: It is not possible to attached another document than a PO
authorJon Alegría <jon.alegria@openbravo.com>
Mon, 01 Oct 2012 12:45:21 +0200
changeset 9899 6c27023b8e86
parent 9898 b3c0e293bfb0
child 9900 4304705abf8e
Fixes issue 0021809: It is not possible to attached another document than a PO
while sending a PO by email.
src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java
--- a/src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java	Tue Sep 25 11:56:27 2012 +0000
+++ b/src/org/openbravo/erpCommon/utility/reporting/printing/PrintController.java	Mon Oct 01 12:45:21 2012 +0200
@@ -57,6 +57,7 @@
 import org.openbravo.base.exception.OBException;
 import org.openbravo.base.secureApp.HttpSecureAppServlet;
 import org.openbravo.base.secureApp.VariablesSecureApp;
+import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.erpCommon.utility.OBError;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
@@ -708,8 +709,8 @@
       if (object != null) {
         final Vector<Object> vector = (Vector<Object>) object;
         for (int i = 0; i < vector.size(); i++) {
-          final AttachContent content = (AttachContent) vector.get(i);
-          final File file = prepareFile(content);
+          final AttachContent objContent = (AttachContent) vector.get(i);
+          final File file = prepareFile(objContent);
           messageBodyPart = new MimeBodyPart();
           messageBodyPart.attachFile(file);
           multipart.addBodyPart(messageBodyPart);
@@ -825,13 +826,13 @@
       isTheFirstEntry = new Boolean(true);
     }
 
-    final AttachContent file = new AttachContent();
     if (vars.getMultiFile("inpFile") != null && !vars.getMultiFile("inpFile").getName().equals("")) {
       final AttachContent content = new AttachContent();
       final FileItem file1 = vars.getMultiFile("inpFile");
-      content.setFileName(file1.getName());
+      content.setFileName(pocData[0].ourreference.replace('/', '_') + '-'
+          + Utility.formatDate(new Date(), "yyyyMMdd-HHmmss") + '.' + file1.getName());
       content.setFileItem(file1);
-      content.setId(file1.getName());
+      content.setId(Utility.formatDate(new Date(), "yyyyMMdd-HHmmss") + '.' + file1.getName());
       content.visible = "hidden";
       if (vars.getStringParameter("inpArchive") == "Y") {
         content.setSelected("true");
@@ -1219,6 +1220,9 @@
    */
   private File prepareFile(AttachContent content) throws ServletException {
     try {
+      final String attachPath = OBPropertiesProvider.getInstance().getOpenbravoProperties()
+          .getProperty("attach.path")
+          + "/tmp";
       final File f = new File(content.getFileName());
       final InputStream inputStream = content.getFileItem().getInputStream();
       final OutputStream out = new FileOutputStream(f);