Skip to content

Commit

Permalink
FIX missing URL in some letters
Browse files Browse the repository at this point in the history
  • Loading branch information
ecino committed Aug 15, 2024
1 parent e772a0a commit aef78a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sbc_compassion/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
# pylint: disable=C8101
{
"name": "Sponsor to Participant communication",
"version": "14.0.1.0.1",
"version": "14.0.1.0.2",
"category": "Compassion",
"summary": "SBC - Supporter to Participant Communication",
"sequence": 150,
Expand Down
8 changes: 8 additions & 0 deletions sbc_compassion/migrations/14.0.1.0.2/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from openupgradelib import openupgrade


@openupgrade.migrate()
def migrate(env, version):
if version:
letters = env["correspondence"].search([("read_url", "=", False), ("uuid", "!=", False)])
letters.with_delay()._compute_read_url()
13 changes: 10 additions & 3 deletions sbc_compassion/models/correspondence.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Correspondence(models.Model):
# Letter remote access
######################
uuid = fields.Char(required=True, default=lambda self: self._get_uuid())
read_url = fields.Char()
read_url = fields.Char(compute="_compute_read_url", store=True)

# 5. SQL Constraints
####################
Expand Down Expand Up @@ -445,6 +445,11 @@ def _compute_valid_language(self):
lang and lang in letter.supporter_languages_ids
)

@api.depends("uuid")
def _compute_read_url(self):
for letter in self:
letter.read_url = f"{letter.get_base_url()}/b2s_image?id={letter.uuid}"

##########################################################################
# ORM METHODS #
##########################################################################
Expand Down Expand Up @@ -735,8 +740,6 @@ def process_letter(self):
self.env["ir.config_parameter"].sudo().get_param("web.external.url", "")
)
self.download_attach_letter_image(letter_type="final_letter_url")
for letter in self:
letter.read_url = f"{base_url}/b2s_image?id={letter.uuid}"
return True

def download_attach_letter_image(self, letter_type="final_letter_url"):
Expand Down Expand Up @@ -1007,6 +1010,10 @@ def create_text_boxes(self):

return paragraphs

def get_base_url(self):
# Use external URL for letter access
return self.env["ir.config_parameter"].sudo().get_param("web.external.url", "")

##########################################################################
# PRIVATE METHODS #
##########################################################################
Expand Down

0 comments on commit aef78a3

Please sign in to comment.