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

[16.0][ADD] attachment_log #3161

Open
wants to merge 8 commits into
base: 16.0
Choose a base branch
from

Conversation

geomer198
Copy link

This module adds the following features for attachments:

  • Displays the date and time when each attachment was added under the attachment file
  • Records chatter messages showing which user linked or unlinked files to attachments

@geomer198 geomer198 force-pushed the 16.0-t4242-attachment-log-add branch from 9b18974 to fc0cd0a Compare January 9, 2025 17:48
message = record.message_post(
body=Markup(
_(
"User <b>%(username)s</b> is attached a new file: <i>%(filename)s</i>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"User <b>%(username)s</b> is attached a new file: <i>%(filename)s</i>"
"<b>%(username)s</b> attached a file: <i>%(filename)s</i>"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would then show as Mitchell Admin attached a file: Invoice.pdf

Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are my concerns: why should we post a message for every attachment added?
What if an incoming email arrives with 10+ attachments in it? It will result in 10+ messages trashing the record chatter.
You can simply show name of the user who added attachment together with the creation date. That is.

"website": "https://github.com/OCA/server-tools",
"license": "AGPL-3",
"category": "Generic Modules",
"depends": ["base", "mail"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to depend on base because mail already depends on it.

Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should add test coverage for the features you are adding.

record = self.env[self.res_model].sudo().browse(self.res_id)
message_text = _(
"<b>%(username)s</b> %(action)s a file: <i>%(filename)s</i>"
) % {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use correct method for string translations.

"summary": "Add log info for attachments",
"website": "https://github.com/OCA/server-tools",
"license": "AGPL-3",
"category": "Generic Modules",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that such category exists? If yes, please share a link to it.

"attachment_log/static/src/components/*/*",
]
},
"installable": True,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True is the default value for this key, no need to add it.

class IrAttachment(models.Model):
_inherit = "ir.attachment"

def _send_attachment_notification(self, is_create=False, is_unlink=False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Posting messages in chatter should be an option that is toggled in the configuration. Because some users might considered it not useful and even annoying.

@@ -0,0 +1,18 @@
{
"name": "Attachment Log",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name is irrelevant because you are not adding any logging. There is no attachment log implemented.
It either logging or tracking.
Suggested name could be "Attachment Logging" with the technical name adjusted accordingly.

"name": "Attachment Log",
"version": "16.0.1.0.0",
"author": "Cetmix, Odoo Community Association (OCA)",
"summary": "Add log info for attachments",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are not adding any log info to attachments. You are showing tracking information or metadata.
So should be something like Show attachment information in chatter.

@@ -0,0 +1,4 @@
This module adds the following features for attachments:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module shows attachment information in chatter. Following data is displayed:

  • User, who has created the attachment
  • Attachment creation date

It also allows to log attachment related actions in the record chatter.

"filename": self.name,
"action": action,
}
message = record.message_post(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use a custom message subtype for such messages in order to allow more flexible configuration.

@geomer198 geomer198 force-pushed the 16.0-t4242-attachment-log-add branch from cd55848 to 7e55b4c Compare January 15, 2025 21:44
@geomer198 geomer198 force-pushed the 16.0-t4242-attachment-log-add branch from 7e55b4c to 81f090d Compare January 15, 2025 21:44
Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add CONFIGURE.rts to explain the configuration process.

To enable note logging of attachment operations in record chatter: 

- Go to "Settings > General Settings" and scroll to the "Discuss" section.
- Activate the "Attachment Logging" checkbox.

Add screenshots that make both configuration and usage easier. Must be not more than 800px width.
Here is an example. Don't use this picture because you need to fix the configuration view first.

image

"name": "Attachment Logging",
"version": "16.0.1.0.0",
"author": "Cetmix, Odoo Community Association (OCA)",
"summary": "Show attachment information in chatter",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show attachment<remove_extra_space_here> information in chatter


use_attachment_log = fields.Boolean(
config_parameter="attachment_logging.use_attachment_log",
help="Log a file operation for record in chatter",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log attachment operations in chatter

@@ -0,0 +1 @@
Module automatically log in chatter the date and time when each attachment was added and which user linked or unlinked files to attachments.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create date and user are displayed next to attachments in chatter.
When attachment is added or removed a note is logged in chatter if the corresponding option is enabled in the General Settings.

<field name="use_attachment_log" />
</div>
<div class="o_setting_right_pane">
<span class="o_form_label">Attachment Log</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Attachment Logging

<div class="o_setting_right_pane">
<span class="o_form_label">Attachment Log</span>
<div class="text-muted col-md-12">
Log attached or unlinked file in chatter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log a note in record chatter when an attachment is added or removed.

<div class="text-muted col-md-12">
Log attached or unlinked file in chatter
</div>
<div
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this twillio div doing here?

Copy link
Member

@ivs-cetmix ivs-cetmix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review LGTM

@yostashiro
Copy link
Member

yostashiro commented Jan 19, 2025

Just noticed that I don't seem to be able to attach a file in a message (upload doesn't complete) when the feature is activated (tested in Runboat). Can you please check?

image

@ivs-cetmix
Copy link
Member

Just noticed that I don't seem to be able to attach a file in a message (upload doesn't complete) when the feature is activated (tested in Runboat). Can you please check?

Hi @yostashiro! Thank you for noticing that! Will fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants