Skip to content

[18.0][dms_field] dms.field.template root directory is created but not displayed and second click raises duplicated directory error #500

Description

@DealTechSrl

Steps to reproduce

  1. Install dms_field.
  2. Create a dms.field.template manually from the UI.
  3. Set:
    • a DMS storage
    • a model
    • one or more DMS access groups
  4. Open the Documents tab of the template.
  5. Click the storage initialization button/icon.

Current behavior

The root dms.directory for the dms.field.template is created in the database, for example:

name = My embedded2
res_model = dms.field.template
res_id = <template_id>
is_root_directory = True
root_directory_id = <same directory id>

However, the newly created directory is not displayed in the DMS widget.

If the user clicks the storage initialization button again, create_dms_directory() tries to create the same root directory again and raises:

A directory with the same name already exists.

In some cases the created directory may also miss the template access groups, making it not readable by a regular user due to DMS record rules

Suggested fix

Make the dms.field.template branch of create_dms_directory() idempotent by returning the existing linked root directory when present, and ensure missing template groups are applied.

Additionally, in the JS controller, include a fallback domain based on:

res_model = dms.field.template
res_id = current template id

so the widget can display the newly created root directory even before the form one2many cache is refreshed.

Could you please confirm whether this is a duplicate of an existing issue or an expected behavior?

If this is confirmed as a bug, we have ready a pull request with the proposed backend and frontend adjustments.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions