Skip to content

Commit

Permalink
Merge PR #301 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Feb 16, 2024
2 parents dbcc877 + 9db3284 commit dc5d258
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 13 deletions.
39 changes: 38 additions & 1 deletion dms/models/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import ast
import base64
import logging
from ast import literal_eval
from collections import defaultdict

from odoo import _, api, fields, models, tools
from odoo.exceptions import UserError, ValidationError
from odoo.osv.expression import OR
from odoo.osv.expression import AND, OR
from odoo.tools import consteq

from odoo.addons.http_routing.models.ir_http import slugify
Expand Down Expand Up @@ -751,3 +752,39 @@ def _search_panel_domain_image(
return super()._search_panel_domain_image(
field_name=field_name, domain=domain, set_count=set_count, limit=limit
)

def action_dms_directories_all_directory(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id(
"dms.action_dms_directory"
)
domain = AND(
[
literal_eval(action["domain"].strip()),
[("parent_id", "child_of", self.id)],
]
)
action["domain"] = domain
action["context"] = dict(
self.env.context,
default_parent_id=self.id,
searchpanel_default_parent_id=self.id,
)
return action

def action_dms_files_all_directory(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id("dms.action_dms_file")
domain = AND(
[
literal_eval(action["domain"].strip()),
[("directory_id", "child_of", self.id)],
]
)
action["domain"] = domain
action["context"] = dict(
self.env.context,
default_directory_id=self.id,
searchpanel_default_directory_id=self.id,
)
return action
12 changes: 12 additions & 0 deletions dms/models/dms_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,18 @@ def search_panel_select_range(self, field_name, **kwargs):
(even if some folders have no files)."""
if field_name == "directory_id":
domain = [["is_hidden", "=", False]]
# If we pass by context something, we filter more about it we filter
# the directories of the files or we show all of them
if self.env.context.get("active_model", False) == "dms.directory":
active_id = self.env.context.get("active_id")
# para saber que directorios, buscamos las posibles carpetas que nos interesan
files = self.env["dms.file"].search(
[["directory_id", "child_of", active_id]]
)
all_directories = files.mapped("directory_id")
all_directories += files.mapped("directory_id.parent_id")
domain.append(["id", "in", all_directories.ids])
# Get all possible directories
comodel_records = (
self.env["dms.directory"]
.with_context(directory_short_name=True)
Expand Down
24 changes: 12 additions & 12 deletions dms/views/directory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -230,17 +230,17 @@
<h6 class="dropdown-header">Views
</h6>
<a
type="action"
name="%(dms.action_dms_directories_all_directory)d"
type="object"
name="action_dms_directories_all_directory"
role="menuitem"
class="dropdown-item"
>
<i class="fa fa-folder-o" />
Directories
</a>
<a
type="action"
name="%(dms.action_dms_files_all_directory)d"
type="object"
name="action_dms_files_all_directory"
role="menuitem"
class="dropdown-item"
>
Expand Down Expand Up @@ -299,17 +299,17 @@
<div class="mk_directory_kanban_actions">
<div class="mk_directory_kanban_actions_wrapper">
<a
type="action"
name="%(dms.action_dms_directories_directory)d"
type="object"
name="action_dms_directories_all_directory"
role="button"
class="btn btn-sm btn-outline-primary mk_directory_kanban_directories"
t-att-title="record.count_directories_title.raw_value"
>
<i class="fa fa-lg fa-folder" />
</a>
<a
type="action"
name="%(dms.action_dms_files_directory)d"
type="object"
name="action_dms_files_all_directory"
role="button"
class="btn btn-sm btn-outline-primary mk_directory_kanban_files"
t-att-title="record.count_files_title.raw_value"
Expand Down Expand Up @@ -402,8 +402,8 @@
<sheet>
<div class="oe_button_box" name="button_box">
<button
type="action"
name="%(dms.action_dms_directories_all_directory)d"
type="object"
name="action_dms_directories_all_directory"
class="oe_stat_button"
icon="fa-folder-open-o"
>
Expand All @@ -414,8 +414,8 @@
/>
</button>
<button
type="action"
name="%(dms.action_dms_files_all_directory)d"
type="object"
name="action_dms_files_all_directory"
class="oe_stat_button"
icon="fa-file-text-o"
>
Expand Down

0 comments on commit dc5d258

Please sign in to comment.