Skip to content

Commit 6c40c37

Browse files
[IMP] document_page: pre-commit auto fixes
1 parent 1e58b4e commit 6c40c37

1 file changed

Lines changed: 33 additions & 20 deletions

File tree

document_page_approval/models/document_page_history.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from odoo import fields, models
66
from odoo.exceptions import UserError
7-
from odoo.tools.translate import _
87

98

109
class DocumentPageHistory(models.Model):
@@ -44,11 +43,11 @@ def action_draft(self):
4443
"""Set a change request as draft"""
4544
for rec in self:
4645
if not rec.state == "cancelled":
47-
raise UserError(_("You need to cancel it before reopening."))
46+
raise UserError(self.env._("You need to cancel it before reopening."))
4847
if not (rec.am_i_owner or rec.am_i_approver):
4948
raise UserError(
50-
_(
51-
"You are not authorized to do this.\r\n"
49+
self.env._(
50+
"You are not authorized to do this.\n"
5251
"Only owners or approvers can reopen Change Requests."
5352
)
5453
)
@@ -64,11 +63,14 @@ def action_to_approve(self):
6463
)
6564
for rec in self:
6665
if rec.state != "draft":
67-
raise UserError(_("Can't approve pages in '%s' state.") % rec.state)
66+
raise UserError(
67+
self.env._("Can't approve pages in '%(state)s' state.")
68+
% {"state": rec.state}
69+
)
6870
if not (rec.am_i_owner or rec.am_i_approver):
6971
raise UserError(
70-
_(
71-
"You are not authorized to do this.\r\n"
72+
self.env._(
73+
"You are not authorized to do this.\n"
7274
"Only owners or approvers can request approval."
7375
)
7476
)
@@ -89,17 +91,21 @@ def action_approve(self):
8991
"""Set a change request as approved."""
9092
for rec in self:
9193
if rec.state not in ["draft", "to approve"]:
92-
raise UserError(_("Can't approve page in '%s' state.") % rec.state)
94+
raise UserError(
95+
self.env._("Can't approve page in '%(state)s' state.")
96+
% {"state": rec.state}
97+
)
9398
if not rec.am_i_approver:
9499
raise UserError(
95-
_(
96-
"You are not authorized to do this.\r\n"
97-
"Only approvers with these groups can approve this: {}"
98-
).format(
99-
", ".join(
100-
[g.display_name for g in rec.page_id.approver_group_ids]
101-
)
100+
self.env._(
101+
"You are not authorized to do this.\n"
102+
"Only approvers with these groups can approve this: %(groups)s"
102103
)
104+
% {
105+
"groups": ", ".join(
106+
g.display_name for g in rec.page_id.approver_group_ids
107+
)
108+
}
103109
)
104110

105111
# Update state
@@ -115,13 +121,15 @@ def action_approve(self):
115121
# Notify state change
116122
rec.message_post(
117123
subtype_xmlid="mail.mt_comment",
118-
body=_("Change request has been approved by %s.")
119-
% (self.env.user.name),
124+
body=self.env._("Change request has been approved by %(user)s.")
125+
% {"user": self.env.user.name},
120126
)
121127
# Notify followers a new version is available
122128
rec.page_id.message_post(
123129
subtype_xmlid="mail.mt_comment",
124-
body=_("New version of the document %s approved.") % (rec.page_id.name),
130+
body=self.env._("New version of the document {} approved.").format(
131+
rec.page_id.name
132+
),
125133
)
126134

127135
def action_cancel(self):
@@ -130,8 +138,13 @@ def action_cancel(self):
130138
for rec in self:
131139
rec.message_post(
132140
subtype_xmlid="mail.mt_comment",
133-
body=_("Change request <b>%(name)s</b> has been cancelled by %(user)s.")
134-
% ({"name": rec.display_name, "user": self.env.user.name}),
141+
body=self.env._(
142+
"Change request <b>%(name)s</b> has been cancelled by %(user)s."
143+
)
144+
% {
145+
"name": rec.display_name,
146+
"user": self.env.user.name,
147+
},
135148
)
136149

137150
def action_cancel_and_draft(self):

0 commit comments

Comments
 (0)