Skip to content

Commit 634325e

Browse files
committed
[19.0][MIG] dms: Migration to 19.0
Signed-off-by: Don Kendall <dkendall@ledoweb.com>
1 parent f33d935 commit 634325e

26 files changed

Lines changed: 228 additions & 144 deletions

dms/controllers/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
class OnboardingController(http.Controller):
8-
@http.route("/config/dms.forbidden_extensions", type="json", auth="user")
8+
@http.route("/config/dms.forbidden_extensions", type="jsonrpc", auth="user")
99
def forbidden_extensions(self, **_kwargs):
1010
params = request.env["ir.config_parameter"].sudo()
1111
return {

dms/demo/res_users.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
-->
88
<odoo noupdate="1">
99
<record id="base.user_demo" model="res.users">
10-
<field eval="[(4, ref('dms.group_dms_user'))]" name="groups_id" />
10+
<field eval="[(4, ref('dms.group_dms_user'))]" name="group_ids" />
1111
</record>
1212
</odoo>

dms/models/access_groups.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright 2024 Timothée Vannier - Subteno (https://www.subteno.com).
44
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
55

6-
from odoo import _, api, fields, models
6+
from odoo import Command, api, fields, models
77
from odoo.exceptions import ValidationError
88

99

@@ -47,7 +47,7 @@ class DmsAccessGroups(models.Model):
4747
string="Directories",
4848
column1="gid",
4949
column2="aid",
50-
auto_join=True,
50+
bypass_search_access=True,
5151
readonly=True,
5252
)
5353
complete_directory_ids = fields.Many2many(
@@ -56,7 +56,7 @@ class DmsAccessGroups(models.Model):
5656
column1="gid",
5757
column2="aid",
5858
string="Complete directories",
59-
auto_join=True,
59+
bypass_search_access=True,
6060
readonly=True,
6161
)
6262
count_users = fields.Integer(compute="_compute_users", store=True)
@@ -94,7 +94,7 @@ class DmsAccessGroups(models.Model):
9494
column2="uid",
9595
string="Group Users",
9696
compute="_compute_users",
97-
auto_join=True,
97+
bypass_search_access=True,
9898
store=True,
9999
recursive=True,
100100
)
@@ -104,9 +104,10 @@ def _compute_count_directories(self):
104104
for record in self:
105105
record.count_directories = len(record.directory_ids)
106106

107-
_sql_constraints = [
108-
("name_uniq", "unique (name)", "The name of the group must be unique!")
109-
]
107+
_name_uniq = models.Constraint(
108+
"unique (name)",
109+
"The name of the group must be unique!",
110+
)
110111

111112
@api.depends(
112113
"parent_group_id.perm_inclusive_create",
@@ -136,20 +137,20 @@ def default_get(self, fields_list):
136137
if res.get("explicit_user_ids"):
137138
res["explicit_user_ids"] = res["explicit_user_ids"] + [self.env.uid]
138139
else:
139-
res["explicit_user_ids"] = [(6, 0, [self.env.uid])]
140+
res["explicit_user_ids"] = [Command.set([self.env.uid])]
140141
return res
141142

142143
@api.depends(
143144
"parent_group_id",
144145
"parent_group_id.users",
145146
"group_ids",
146-
"group_ids.users",
147+
"group_ids.user_ids",
147148
"explicit_user_ids",
148149
)
149150
def _compute_users(self):
150151
for record in self:
151152
users = (
152-
record.group_ids.users
153+
record.group_ids.user_ids
153154
| record.explicit_user_ids
154155
| record.parent_group_id.users
155156
)
@@ -158,7 +159,7 @@ def _compute_users(self):
158159
def copy_data(self, default=None):
159160
vals_list = super().copy_data(default)
160161
for group, vals in zip(self, vals_list, strict=False):
161-
vals["name"] = _("%s (copy)") % group.name
162+
vals["name"] = self.env._("%s (copy)", group.name)
162163
return vals_list
163164

164165
@api.constrains("parent_path")
@@ -169,9 +170,9 @@ def _check_parent_recursiveness(self):
169170
for one in self.filtered("parent_group_id"):
170171
if str(one.id) in one.parent_path.split("/"):
171172
raise ValidationError(
172-
_("Parent group '%(parent)s' is child of '%(current)s'.")
173-
% {
174-
"parent": one.parent_group_id.display_name,
175-
"current": one.display_name,
176-
}
173+
self.env._(
174+
"Parent group '%(parent)s' is child of '%(current)s'.",
175+
parent=one.parent_group_id.display_name,
176+
current=one.display_name,
177+
)
177178
)

dms/models/directory.py

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
from collections import defaultdict
1313
from typing import Literal # noqa # pylint: disable=unused-import
1414

15-
from odoo import _, api, fields, models, tools
15+
from odoo import api, fields, models, tools
1616
from odoo.exceptions import UserError, ValidationError
17-
from odoo.osv.expression import AND, OR
17+
from odoo.fields import Domain
1818
from odoo.tools import consteq, human_size
1919

2020
from ..tools.file import check_name, unique_name
@@ -60,7 +60,7 @@ class DmsDirectory(models.Model):
6060
comodel_name="dms.storage",
6161
string="Storage",
6262
ondelete="restrict",
63-
auto_join=True,
63+
bypass_search_access=True,
6464
store=True,
6565
)
6666
parent_id = fields.Many2one(
@@ -116,7 +116,7 @@ def _default_parent_id(self):
116116
comodel_name="dms.directory",
117117
inverse_name="parent_id",
118118
string="Subdirectories",
119-
auto_join=False,
119+
bypass_search_access=False,
120120
copy=True,
121121
)
122122

@@ -153,7 +153,7 @@ def _default_parent_id(self):
153153
comodel_name="dms.file",
154154
inverse_name="directory_id",
155155
string="Files",
156-
auto_join=False,
156+
bypass_search_access=False,
157157
copy=True,
158158
)
159159

@@ -221,7 +221,7 @@ def _get_domain_by_access_groups(self, operation):
221221
if operation == "create":
222222
# When creating, I need create access in parent directory, or
223223
# self-create permission if it's a root directory
224-
result = OR(
224+
result = Domain.OR(
225225
[
226226
[("is_root_directory", "=", False)] + result,
227227
[("is_root_directory", "=", True)] + self_filter,
@@ -376,10 +376,9 @@ def _search_panel_directory(self, **kwargs):
376376
return domain[1], domain[2]
377377
return None, None
378378

379-
# Search
380379
@api.model
381380
def _search_starred(self, operator, operand):
382-
if operator == "=" and operand:
381+
if operator in ("=", "in") and operand:
383382
return [("user_star_ids", "in", [self.env.uid])]
384383
return [("user_star_ids", "not in", [self.env.uid])]
385384

@@ -412,14 +411,16 @@ def _compute_count_directories(self):
412411
for record in self:
413412
directories = len(record.child_directory_ids)
414413
record.count_directories = directories
415-
record.count_directories_title = _("%s Subdirectories") % directories
414+
record.count_directories_title = self.env._(
415+
"%s Subdirectories", directories
416+
)
416417

417418
@api.depends("file_ids")
418419
def _compute_count_files(self):
419420
for record in self:
420421
files = len(record.file_ids)
421422
record.count_files = files
422-
record.count_files_title = _("%s Files") % files
423+
record.count_files_title = self.env._("%s Files", files)
423424

424425
@api.depends("child_directory_ids", "file_ids")
425426
def _compute_count_elements(self):
@@ -528,7 +529,9 @@ def _onchange_model_id(self):
528529
@api.constrains("parent_id")
529530
def _check_directory_recursion(self):
530531
if self._has_cycle():
531-
raise ValidationError(_("Error! You cannot create recursive directories."))
532+
raise ValidationError(
533+
self.env._("Error! You cannot create recursive directories.")
534+
)
532535
return True
533536

534537
@api.constrains("storage_id", "model_id")
@@ -538,34 +541,40 @@ def _check_storage_id_attachment_model_id(self):
538541
):
539542
if not record.model_id:
540543
raise ValidationError(
541-
_("A directory has to have model in attachment storage.")
544+
self.env._("A directory has to have model in attachment storage.")
542545
)
543546
if not record.is_root_directory and not record.res_id:
544547
raise ValidationError(
545-
_("This directory needs to be associated to a record.")
548+
self.env._("This directory needs to be associated to a record.")
546549
)
547550

548551
@api.constrains("is_root_directory", "storage_id")
549552
def _check_directory_storage(self):
550553
for record in self:
551554
if record.is_root_directory and not record.storage_id:
552-
raise ValidationError(_("A root directory has to have a storage."))
555+
raise ValidationError(
556+
self.env._("A root directory has to have a storage.")
557+
)
553558

554559
@api.constrains("is_root_directory", "parent_id")
555560
def _check_directory_parent(self):
556561
for record in self:
557562
if record.is_root_directory and record.parent_id:
558563
raise ValidationError(
559-
_("A directory can't be a root and have a parent directory.")
564+
self.env._(
565+
"A directory can't be a root and have a parent directory."
566+
)
560567
)
561568
if not record.is_root_directory and not record.parent_id:
562-
raise ValidationError(_("A directory has to have a parent directory."))
569+
raise ValidationError(
570+
self.env._("A directory has to have a parent directory.")
571+
)
563572

564573
@api.constrains("name")
565574
def _check_name(self):
566575
for record in self:
567576
if self.env.context.get("check_name", True) and not check_name(record.name):
568-
raise ValidationError(_("The directory name is invalid."))
577+
raise ValidationError(self.env._("The directory name is invalid."))
569578
if record.is_root_directory:
570579
children = record.sudo().storage_id.root_directory_ids
571580
else:
@@ -576,7 +585,7 @@ def _check_name(self):
576585
and child != record
577586
):
578587
raise ValidationError(
579-
_("A directory with the same name already exists.")
588+
self.env._("A directory with the same name already exists.")
580589
)
581590

582591
# Create, Update, Delete
@@ -626,7 +635,7 @@ def message_new(self, msg_dict, custom_values=None):
626635
return parent_directory
627636
names = parent_directory.child_directory_ids.mapped("name")
628637
slug = self.env["ir.http"]._slug
629-
subject = slug(msg_dict.get("subject", _("Alias-Mail-Extraction")))
638+
subject = slug(msg_dict.get("subject", self.env._("Alias-Mail-Extraction")))
630639
defaults = dict(
631640
{"name": unique_name(subject, names, escape_suffix=True)}, **custom_values
632641
)
@@ -678,13 +687,15 @@ def write(self, vals):
678687
if new_parent_id:
679688
if old_storage_id != self.browse(new_parent_id).storage_id.id:
680689
raise UserError(
681-
_(
690+
self.env._(
682691
"It is not possible to change to a parent "
683692
"with other storage."
684693
)
685694
)
686695
elif old_storage_id != new_storage_id:
687-
raise UserError(_("It is not possible to change the storage."))
696+
raise UserError(
697+
self.env._("It is not possible to change the storage.")
698+
)
688699
# Groups part
689700
if any(key in vals for key in ["group_ids", "inherit_group_ids"]):
690701
res = super().write(vals)
@@ -743,7 +754,7 @@ def action_dms_directories_all_directory(self):
743754
action = self.env["ir.actions.act_window"]._for_xml_id(
744755
"dms.action_dms_directory"
745756
)
746-
domain = AND(
757+
domain = Domain.AND(
747758
[
748759
literal_eval(action["domain"].strip()),
749760
[("parent_id", "child_of", self.id)],
@@ -761,7 +772,7 @@ def action_dms_directories_all_directory(self):
761772
def action_dms_files_all_directory(self):
762773
self.ensure_one()
763774
action = self.env["ir.actions.act_window"]._for_xml_id("dms.action_dms_file")
764-
domain = AND(
775+
domain = Domain.AND(
765776
[
766777
literal_eval(action["domain"].strip()),
767778
[("directory_id", "child_of", self.id)],

dms/models/dms_category.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import logging
77

8-
from odoo import _, api, fields, models
8+
from odoo import api, fields, models
99
from odoo.exceptions import ValidationError
1010

1111
_logger = logging.getLogger(__name__)
@@ -63,9 +63,10 @@ class DMSCategory(models.Model):
6363
count_directories = fields.Integer(compute="_compute_count_directories")
6464
count_files = fields.Integer(compute="_compute_count_files")
6565

66-
_sql_constraints = [
67-
("name_uniq", "unique (name)", "Category name already exists!"),
68-
]
66+
_name_uniq = models.Constraint(
67+
"unique (name)",
68+
"Category name already exists!",
69+
)
6970

7071
@api.depends("name", "parent_id.complete_name")
7172
def _compute_complete_name(self):
@@ -100,5 +101,7 @@ def _compute_count_files(self):
100101
@api.constrains("parent_id")
101102
def _check_category_recursion(self):
102103
if self._has_cycle():
103-
raise ValidationError(_("Error! You cannot create recursive categories."))
104+
raise ValidationError(
105+
self.env._("Error! You cannot create recursive categories.")
106+
)
104107
return True

0 commit comments

Comments
 (0)