From caf1e8cf6bb1d8fe51fc62a2421916b653b48039 Mon Sep 17 00:00:00 2001 From: Daniel Gergely Date: Mon, 2 Nov 2026 11:13:06 +0100 Subject: [PATCH] [T3616] FIX: no letter image on pages added for overflowing text --- sbc_compassion/__manifest__.py | 2 +- .../migrations/18.0.1.0.7/post-migration.py | 26 +++++++++++++++++++ sbc_compassion/models/correspondence_page.py | 12 ++++++--- 3 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 sbc_compassion/migrations/18.0.1.0.7/post-migration.py diff --git a/sbc_compassion/__manifest__.py b/sbc_compassion/__manifest__.py index 8a18cc963..f1523dfd0 100644 --- a/sbc_compassion/__manifest__.py +++ b/sbc_compassion/__manifest__.py @@ -28,7 +28,7 @@ # pylint: disable=C8101 { "name": "Sponsor to Participant communication", - "version": "18.0.1.0.6", + "version": "18.0.1.0.7", "category": "Compassion", "summary": "SBC - Supporter to Participant Communication", "sequence": 150, diff --git a/sbc_compassion/migrations/18.0.1.0.7/post-migration.py b/sbc_compassion/migrations/18.0.1.0.7/post-migration.py new file mode 100644 index 000000000..0a96107e9 --- /dev/null +++ b/sbc_compassion/migrations/18.0.1.0.7/post-migration.py @@ -0,0 +1,26 @@ +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + # T3616: pages added to hold overflowing translations got a crop of the + # letter image as background. They are not part of the scanned letter. + pages = env["correspondence.page"].search( + [ + ("original_page_url", "=", False), + "|", + ("cloudinary_original_page_url", "!=", False), + ("cloudinary_final_page_url", "!=", False), + ] + ) + pages = pages.filtered( + lambda page: page.correspondence_id.page_ids.filtered("original_page_url") + ) + _logger.info("Remove the letter image from %s added pages", len(pages)) + pages.write( + {"cloudinary_original_page_url": False, "cloudinary_final_page_url": False} + ) diff --git a/sbc_compassion/models/correspondence_page.py b/sbc_compassion/models/correspondence_page.py index b23de1817..6e85e0d7f 100644 --- a/sbc_compassion/models/correspondence_page.py +++ b/sbc_compassion/models/correspondence_page.py @@ -188,16 +188,20 @@ def _get_cloudinary_url(self, cloudinary_url): """ Returns the cloudinary url with the correct crop so that the page is displayed """ - if not cloudinary_url: + # Pages added to hold overflowing text are not part of the letter image + letter_pages = self.correspondence_id.page_ids + scanned_pages = letter_pages.filtered("original_page_url") or letter_pages + if not cloudinary_url or self not in scanned_pages: return False + scanned_index = list(scanned_pages).index(self) + 1 if cloudinary_url.endswith("p1.jpg"): - return cloudinary_url.replace("p1.jpg", f"p{str(self.page_index)}.jpg") + return cloudinary_url.replace("p1.jpg", f"p{scanned_index}.jpg") response = requests.get(cloudinary_url, timeout=3) if not response.ok: return False width, total_height = Image.open(BytesIO(response.content)).size - height = total_height // len(self.correspondence_id.page_ids) - y_start = (self.page_index - 1) * height + height = total_height // len(scanned_pages) + y_start = (scanned_index - 1) * height crop_operator = f"c_crop,h_{height},w_{width},x_0,y_{y_start}" url_parts = cloudinary_url.split("upload/") return f"{url_parts[0]}upload/{crop_operator}/{url_parts[1]}"