Skip to content
Merged
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
23 changes: 9 additions & 14 deletions sbc_compassion/models/correspondence.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

_logger = logging.getLogger(__name__)

ROWS_PER_ATTACHMENT_PAGE = 2


class CorrespondenceType(models.Model):
_name = "correspondence.type"
Expand Down Expand Up @@ -1124,30 +1126,23 @@ def _process_gmc_text(self, letter_vals):
def get_attachments_per_page(self, flatten=False):
"""
Used for the S2B report generation
We group 4 attachements per page, 2 per row.
We also convert them on the fly to jpg small size image.
We group 2 attachments per page, 1 per row, so that each picture takes
about half a page like it did with the previous FPDF layout (T3442).
We also convert them on the fly to jpg.
:param flatten: If True, we return a flat list of images
"""
self.ensure_one()
attachments = self.original_attachment_ids.filtered(
lambda a: a.mimetype.startswith("image")
)
images = {0: {0: []}}
page, row = 0, 0

for attachment in attachments:
for index, attachment in enumerate(attachments):
img_data = image_process(
base64.b64decode(attachment.datas), size=(400, 400), quality=75
base64.b64decode(attachment.datas), size=(1600, 1600), quality=85
)
images[page][row].append(base64.b64encode(img_data))
if len(images[page][row]) == 2:
row += 1
images[page][row] = []

if row == 2:
page += 1
row = 0
images[page] = {row: []}
page, row = divmod(index, ROWS_PER_ATTACHMENT_PAGE)
images.setdefault(page, {})[row] = [base64.b64encode(img_data)]

if flatten:
flat_images = []
Expand Down
13 changes: 8 additions & 5 deletions sbc_compassion/reports/correspondence_report.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,19 @@
t-foreach="attachments_page_value"
t-as="attachments_row"
>
<div class="row mx-5 my-5">
<div class="row mx-3 my-4">
<t
t-foreach="attachments_row_value"
t-as="attachment"
>
<div class="col-6 px-4">
<img
<div class="col-12 px-4">
<!-- Aspect-ratio box: wkhtmltopdf renders
CSS mm at ~0.8x, so size relative to the
page width and let the background fit
inside without distorting the picture. -->
<div
t-if="attachment"
t-attf-src="data:image/jpeg;base64,{{attachment}}"
class="w-100"
t-attf-style="height: 0; padding-bottom: 70%; background-image: url('data:image/jpeg;base64,{{attachment}}'); background-size: contain; background-position: center; background-repeat: no-repeat;"
/>
</div>
</t>
Expand Down
Loading