Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[15.0][FIX] dms: Fix smartbuttons from files and directories #293

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, human_size

from odoo.addons.http_routing.models.ir_http import slugify
Expand Down Expand Up @@ -757,3 +758,39 @@
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(

Check warning on line 764 in dms/models/directory.py

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L763-L764

Added lines #L763 - L764 were not covered by tests
"dms.action_dms_directory"
)
domain = AND(

Check warning on line 767 in dms/models/directory.py

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L767

Added line #L767 was not covered by tests
[
literal_eval(action["domain"].strip()),
[("parent_id", "child_of", self.id)],
]
)
action["domain"] = domain
action["context"] = dict(

Check warning on line 774 in dms/models/directory.py

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L773-L774

Added lines #L773 - L774 were not covered by tests
self.env.context,
default_parent_id=self.id,
searchpanel_default_parent_id=self.id,
)
return action

Check warning on line 779 in dms/models/directory.py

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L779

Added line #L779 was not covered by tests

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(

Check warning on line 784 in dms/models/directory.py

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L782-L784

Added lines #L782 - L784 were not covered by tests
[
literal_eval(action["domain"].strip()),
[("directory_id", "child_of", self.id)],
]
)
action["domain"] = domain
action["context"] = dict(

Check warning on line 791 in dms/models/directory.py

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L790-L791

Added lines #L790 - L791 were not covered by tests
self.env.context,
default_directory_id=self.id,
searchpanel_default_directory_id=self.id,
)
return action

Check warning on line 796 in dms/models/directory.py

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L796

Added line #L796 was not covered by tests
12 changes: 12 additions & 0 deletions dms/models/dms_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@
(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")

Check warning on line 309 in dms/models/dms_file.py

View check run for this annotation

Codecov / codecov/patch

dms/models/dms_file.py#L309

Added line #L309 was not covered by tests
# para saber que directorios, buscamos las posibles carpetas que nos interesan
files = self.env["dms.file"].search(

Check warning on line 311 in dms/models/dms_file.py

View check run for this annotation

Codecov / codecov/patch

dms/models/dms_file.py#L311

Added line #L311 was not covered by tests
[["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])

Check warning on line 316 in dms/models/dms_file.py

View check run for this annotation

Codecov / codecov/patch

dms/models/dms_file.py#L314-L316

Added lines #L314 - L316 were not covered by tests
# 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 @@ -231,17 +231,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 @@ -300,17 +300,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 @@ -403,8 +403,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 @@ -415,8 +415,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
Loading