Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] Download filename only contains created date when title is empty, even though correspondent is set
### Description

When a document has not title, but a correspondent: When downloading such a document, the filename only contains the create date followed by a space and then the extension. So the correspondent is missing in the filename, even though it's set. As soon as that document has a title which is not empty, the filename contains the create date, the correspondent and the title.
What should happen: Even when there's no title, the filename should still contain the create date and the correspondent if they are != "".

### Steps to reproduce

1. Upload a sample document
2. Fill out the create date and the correspondent but NOT the title.
3. Click the download button for this document.

### Webserver logs

Nothing gets logged when reproducing this issue.


### Paperless-ngx version

1.7.1

### Host OS

Debian 11

### Installation method

Docker

### Browser

Brave 1.39.111

### Configuration changes

_No response_

### Other

_No response_


Discussion:
Well, I wouldn't say this is a bug exactly.  This formatting has been mostly this way since the project was just paperless.  I imagine It's pretty unexpected to have a document with no title.

It is changeable though, if there is a desire from the community for it.
I agree, what really is the use case for no title anyway?
@stumpylog Thanks for your quick response. :)  I get your point and at the same time just because something has been working incorrectly for a long time doesn't make it right. I think I can prove to you, that this is a bug. Simply because paperless-ngx obviously wants to put something after the created date by already placing a space after the created date:
![image](https://user-images.githubusercontent.com/864660/171203136-210d3529-4a20-4a76-9581-f4c51675f64c.png)

So I would love to see this fixed, since there already is that space and only the correspondent string is missing. :)
@shamoon In my case for example I've got a lot of documents which are perfectly described by the created date, the correspondent and the document type. No further information like a title needed. This is the case for documents of recurring things like loan, subscriptions etc.
The space following the date is only there because the title is blank.  Normally, it would be the space followed by title.  Not really a bug, just an unexpected user use case.

The good new is, despite this coming from a pretty fundamental location, it doesn't appear to break anything to change this.

Resolving patch:
diff --git a/src/documents/models.py b/src/documents/models.py
--- a/src/documents/models.py
+++ b/src/documents/models.py
@@ -233,10 +233,13 @@ def __str__(self):
         # Convert UTC database time to local time
         created = datetime.date.isoformat(timezone.localdate(self.created))
 
-        if self.correspondent and self.title:
-            return f"{created} {self.correspondent} {self.title}"
-        else:
-            return f"{created} {self.title}"
+        res = f"{created}"
+
+        if self.correspondent:
+            res += f" {self.correspondent}"
+        if self.title:
+            res += f" {self.title}"
+        return res
 
     @property
     def source_path(self):


Test patch: