Coverage for ingadhoc-odoo-saas-adhoc / saas_provider_upgrade / models / saas_upgrade_line_request_log_entry.py: 44%
40 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 19:24 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-09 19:24 +0000
1from odoo import api, fields, models
3DIGEST_MAX_LENGTH = 75
6class SaasUpgradeLineRequestLogEntry(models.Model):
7 _name = "saas.upgrade.line.request.log.entry"
8 _description = "Request Entry Log"
9 _order = "id desc"
11 log_id = fields.Many2one(
12 "saas.upgrade.line.request.log",
13 ondelete="cascade",
14 readonly=True,
15 index=True,
16 )
17 request_id = fields.Many2one(
18 "helpdesk.ticket.upgrade.request",
19 string="Request",
20 ondelete="cascade",
21 index=True,
22 readonly=True,
23 )
24 content = fields.Text(
25 readonly=True,
26 )
27 content_digest = fields.Char(
28 compute="_compute_content_digest",
29 )
30 upgrade_line_id = fields.Many2one(
31 related="log_id.upgrade_line_id",
32 )
33 script_id = fields.Many2one(
34 "saas.upgrade.line.script",
35 help="Script version that generated this log entry",
36 )
37 type = fields.Selection(
38 related="log_id.type",
39 )
40 upgrade_ticket_id = fields.Many2one(
41 related="request_id.ticket_id",
42 string="Upgrade Ticket",
43 )
44 ticket_id = fields.Many2one(
45 related="log_id.ticket_id",
46 store=True,
47 )
48 solved = fields.Boolean(
49 related="log_id.solved",
50 store=True,
51 readonly=False,
52 )
54 @api.depends("log_id")
55 def _compute_display_name(self):
56 for rec in self:
57 rec.display_name = f"{rec.log_id.display_name} - {rec.id}"
59 @api.depends("content")
60 def _compute_content_digest(self):
61 for rec in self:
62 if rec.content:
63 rec.content_digest = rec.content[:DIGEST_MAX_LENGTH]
64 rec.content_digest += "..." if len(rec.content) > DIGEST_MAX_LENGTH else ""
65 else:
66 rec.content_digest = False
68 def action_open_upgrade_line(self):
69 self.ensure_one()
70 action = self.upgrade_line_id.get_formview_action()
71 action["context"].update({"ticket_request_id": self.request_id.id})
72 return action
74 def run(self) -> dict | None:
75 """
76 Method to run the upgrade line associated to the parent log, in the request of the entries.
78 :return: The action that indicates that the process is running in background, or None if nothing was run
79 """
80 action = None
81 for rec in self:
82 request = rec.request_id
83 if not request.with_original_database and not request.with_upgraded_database:
84 continue
85 action = rec.log_id.upgrade_line_id.with_context(ticket_request_id=rec.request_id.id)._prepare_run()
86 return action