Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

T1756 - Fix B2S letter attachment #1957

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions partner_communication_compassion/models/correspondence.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,30 +86,6 @@ def get_image(self):
data = super().get_image()
return data

def attach_zip(self):
"""
When a partner gets multiple letters, we make a zip and attach it
to the first letter, so that he can only download this zip.
:return: True
"""
if len(self) > 5:
_zip = (
self.env["correspondence.download.wizard"]
.with_context(active_model=self._name, active_ids=self.ids)
.create({})
)
_zip.get_letters()
self.write({"zip_file": False})
letter_attach = self[:1]
letter_attach.write(
{"zip_file": _zip.download_data, "letter_format": "zip"}
)
base_url = (
self.env["ir.config_parameter"].sudo().get_param("web.external.url")
)
self.write({"read_url": f"{base_url}/b2s_image?id={letter_attach.uuid}"})
return True

def compose_letter_image(self):
"""
Regenerate communication if already existing
Expand Down
36 changes: 16 additions & 20 deletions partner_communication_compassion/models/partner_communication.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PartnerCommunication(models.Model):

def get_correspondence_attachments(self, letters=None):
"""
Include PDF of letters if the send_mode is to print the letters.
Include PDF of letters.
:return: dict {attachment_name: [report_name, pdf_data]}
"""
self.ensure_one()
Expand All @@ -35,25 +35,21 @@ def get_correspondence_attachments(self, letters=None):
report = "partner_communication.a4_communication"
if letters is None:
letters = self.get_objects()
if self.send_mode == "physical":
for letter in letters:
try:
attachments[letter.file_name] = [
report,
self._convert_pdf(letter.letter_image),
]
except MissingError:
_logger.warning("Missing letter image", exc_info=True)
self.send_mode = False
self.auto_send = False
self.message_post(
body=_("The letter image is missing!"),
subject=_("Missing letter"),
)
continue
else:
# Attach directly a zip in the letters
letters.attach_zip()
for letter in letters:
try:
attachments[letter.file_name] = [
report,
self._convert_pdf(letter.letter_image),
]
except MissingError:
_logger.warning("Missing letter image", exc_info=True)
self.send_mode = False
self.auto_send = False
self.message_post(
body=_("The letter image is missing!"),
subject=_("Missing letter"),
)
continue
return attachments

def final_letter_attachment(self):
Expand Down
Loading