Skip to content

Commit

Permalink
[FIX] dms: fix directory files action
Browse files Browse the repository at this point in the history
If the directory is empty, the action would return all files,
and the panel show all directories except for the one that triggered the action.

The file count was not consistent with the action if the directory is
hidden, since its files would thus also be hidden; this field is a
related on the storage, so the value is consistent for the directory and
all its files.
  • Loading branch information
len-foss committed Dec 18, 2023
1 parent d3f3c9c commit e2f8ed8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
23 changes: 22 additions & 1 deletion dms/models/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,33 @@ def _compute_count_total_directories(self):
)
record.count_total_directories = count - 1 if count > 0 else 0

def _get_directory_files_domain(self):
self.ensure_one()
return [
("directory_id", "child_of", self.id),
("is_hidden", "=", self.is_hidden),
]

def action_dms_files_all_directory(self):
self.ensure_one()
return {

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

View check run for this annotation

Codecov / codecov/patch

dms/models/directory.py#L457-L458

Added lines #L457 - L458 were not covered by tests
"type": "ir.actions.act_window",
"name": _("Files"),
"res_model": "dms.file",
"view_mode": "tree,form",
"domain": self._get_directory_files_domain(),
"context": {
"default_directory_id": self.id,
"searchpanel_default_directory_id": self.id,
},
}

def _compute_count_total_files(self):
model = self.env["dms.file"]
for record in self:
# Prevent error in some NewId cases
record.count_total_files = (
model.search_count([("directory_id", "child_of", record.id)])
model.search_count(record._get_directory_files_domain())
if record.id
else 0
)
Expand Down
32 changes: 4 additions & 28 deletions dms/views/directory.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,6 @@
</p>
</field>
</record>
<record id="action_dms_files_all_directory" model="ir.actions.act_window">
<field name="name">Files</field>
<field name="res_model">dms.file</field>
<field name="view_mode">kanban,tree,graph,pivot,form</field>
<field name="domain">
[
("is_hidden", "=", False),
]
</field>
<field name="context">
{
'default_directory_id': active_id,
'searchpanel_default_directory_id': active_id
}
</field>
<field name="help" type="html">
<p class="o_view_nocontent_smiling_face">
Click to add a new file.
</p>
<p>
Files are used to save content directly in Odoo.
</p>
</field>
</record>
<record id="search_dms_directory" model="ir.ui.view">
<field name="name">dms_directory.search</field>
<field name="model">dms.directory</field>
Expand Down Expand Up @@ -240,8 +216,8 @@
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 @@ -415,8 +391,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 e2f8ed8

Please sign in to comment.