1212from collections import defaultdict
1313from 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
1616from odoo .exceptions import UserError , ValidationError
1717from odoo .osv .expression import AND , OR
1818from odoo .tools import consteq , human_size
@@ -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
@@ -412,14 +412,16 @@ def _compute_count_directories(self):
412412 for record in self :
413413 directories = len (record .child_directory_ids )
414414 record .count_directories = directories
415- record .count_directories_title = _ ("%s Subdirectories" ) % directories
415+ record .count_directories_title = self .env ._ (
416+ "%s Subdirectories" , directories
417+ )
416418
417419 @api .depends ("file_ids" )
418420 def _compute_count_files (self ):
419421 for record in self :
420422 files = len (record .file_ids )
421423 record .count_files = files
422- record .count_files_title = _ ("%s Files" ) % files
424+ record .count_files_title = self . env . _ ("%s Files" , files )
423425
424426 @api .depends ("child_directory_ids" , "file_ids" )
425427 def _compute_count_elements (self ):
@@ -528,7 +530,9 @@ def _onchange_model_id(self):
528530 @api .constrains ("parent_id" )
529531 def _check_directory_recursion (self ):
530532 if self ._has_cycle ():
531- raise ValidationError (_ ("Error! You cannot create recursive directories." ))
533+ raise ValidationError (
534+ self .env ._ ("Error! You cannot create recursive directories." )
535+ )
532536 return True
533537
534538 @api .constrains ("storage_id" , "model_id" )
@@ -538,34 +542,40 @@ def _check_storage_id_attachment_model_id(self):
538542 ):
539543 if not record .model_id :
540544 raise ValidationError (
541- _ ("A directory has to have model in attachment storage." )
545+ self . env . _ ("A directory has to have model in attachment storage." )
542546 )
543547 if not record .is_root_directory and not record .res_id :
544548 raise ValidationError (
545- _ ("This directory needs to be associated to a record." )
549+ self . env . _ ("This directory needs to be associated to a record." )
546550 )
547551
548552 @api .constrains ("is_root_directory" , "storage_id" )
549553 def _check_directory_storage (self ):
550554 for record in self :
551555 if record .is_root_directory and not record .storage_id :
552- raise ValidationError (_ ("A root directory has to have a storage." ))
556+ raise ValidationError (
557+ self .env ._ ("A root directory has to have a storage." )
558+ )
553559
554560 @api .constrains ("is_root_directory" , "parent_id" )
555561 def _check_directory_parent (self ):
556562 for record in self :
557563 if record .is_root_directory and record .parent_id :
558564 raise ValidationError (
559- _ ("A directory can't be a root and have a parent directory." )
565+ self .env ._ (
566+ "A directory can't be a root and have a parent directory."
567+ )
560568 )
561569 if not record .is_root_directory and not record .parent_id :
562- raise ValidationError (_ ("A directory has to have a parent directory." ))
570+ raise ValidationError (
571+ self .env ._ ("A directory has to have a parent directory." )
572+ )
563573
564574 @api .constrains ("name" )
565575 def _check_name (self ):
566576 for record in self :
567577 if self .env .context .get ("check_name" , True ) and not check_name (record .name ):
568- raise ValidationError (_ ("The directory name is invalid." ))
578+ raise ValidationError (self . env . _ ("The directory name is invalid." ))
569579 if record .is_root_directory :
570580 children = record .sudo ().storage_id .root_directory_ids
571581 else :
@@ -576,7 +586,7 @@ def _check_name(self):
576586 and child != record
577587 ):
578588 raise ValidationError (
579- _ ("A directory with the same name already exists." )
589+ self . env . _ ("A directory with the same name already exists." )
580590 )
581591
582592 # Create, Update, Delete
@@ -626,7 +636,7 @@ def message_new(self, msg_dict, custom_values=None):
626636 return parent_directory
627637 names = parent_directory .child_directory_ids .mapped ("name" )
628638 slug = self .env ["ir.http" ]._slug
629- subject = slug (msg_dict .get ("subject" , _ ("Alias-Mail-Extraction" )))
639+ subject = slug (msg_dict .get ("subject" , self . env . _ ("Alias-Mail-Extraction" )))
630640 defaults = dict (
631641 {"name" : unique_name (subject , names , escape_suffix = True )}, ** custom_values
632642 )
@@ -678,13 +688,15 @@ def write(self, vals):
678688 if new_parent_id :
679689 if old_storage_id != self .browse (new_parent_id ).storage_id .id :
680690 raise UserError (
681- _ (
691+ self . env . _ (
682692 "It is not possible to change to a parent "
683693 "with other storage."
684694 )
685695 )
686696 elif old_storage_id != new_storage_id :
687- raise UserError (_ ("It is not possible to change the storage." ))
697+ raise UserError (
698+ self .env ._ ("It is not possible to change the storage." )
699+ )
688700 # Groups part
689701 if any (key in vals for key in ["group_ids" , "inherit_group_ids" ]):
690702 res = super ().write (vals )
0 commit comments