Skip to content

Commit b6db131

Browse files
committed
[IMP] contentgrid: Allow to send to ContentGrid lateron
1 parent df0e5a8 commit b6db131

File tree

14 files changed

+154
-16
lines changed

14 files changed

+154
-16
lines changed

contentgrid/README.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,21 @@ of it in contentgrid and a link to the app:
137137

138138
|ContentGrid Popup|
139139

140+
Also, related records will show the same icon in the thread menu and
141+
will allow us to check the data sent to ContentGrid.
142+
143+
|ContentGrid Thread|
144+
145+
In case we want to force the send, we can do it manually by using the
146+
*Allow manual send* field on the configuration. This will show a button
147+
that sends the data to content grid (only attachments not sent)
148+
149+
|image1|
150+
140151
.. |ContentGrid Attachment| image:: https://raw.githubusercontent.com/dixmit/contentgrid/18.0/contentgrid/static/img/contentgrid_attachment.png
141152
.. |ContentGrid Popup| image:: https://raw.githubusercontent.com/dixmit/contentgrid/18.0/contentgrid/static/img/contentgrid_popup.png
153+
.. |ContentGrid Thread| image:: https://raw.githubusercontent.com/dixmit/contentgrid/18.0/contentgrid/static/img/contentgrid_thread.png
154+
.. |image1| image:: https://raw.githubusercontent.com/dixmit/contentgrid/18.0/contentgrid/static/img/contentgrid_thread_force.png
142155

143156
Bug Tracker
144157
===========

contentgrid/models/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
from . import ir_attachment
33
from . import contentgrid_record
44
from . import contentgrid_connection
5+
from . import mail_thread

contentgrid/models/contentgrid_configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ class ContentgridConfiguration(models.Model):
4747
comodel_name="contentgrid.connection", required=True
4848
)
4949
configuration_data = fields.Text(required=True)
50+
allow_manual_send = fields.Boolean(
51+
default=False,
52+
)
5053

5154
@api.constrains("configuration_data")
5255
def _check_configuration_data(self):

contentgrid/models/ir_attachment.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class IrAttachment(models.Model):
1717
ondelete="cascade",
1818
)
1919

20-
def _push_to_contentgrid(self):
20+
def _push_to_contentgrid(self, manual_send=False):
2121
self.ensure_one()
2222
if self.contentgrid_ids:
2323
return
@@ -26,12 +26,13 @@ def _push_to_contentgrid(self):
2626
record = self.env[self.res_model].browse(self.res_id).exists()
2727
if not record:
2828
return
29-
for contentgrid_config in self.env["contentgrid.configuration"].search(
30-
[
31-
("model_id.model", "=", self.res_model),
32-
("active", "=", True),
33-
],
34-
):
29+
domain = [
30+
("model_id.model", "=", self.res_model),
31+
("active", "=", True),
32+
]
33+
if manual_send:
34+
domain.append(("allow_manual_send", "=", True))
35+
for contentgrid_config in self.env["contentgrid.configuration"].search(domain):
3536
contentgrid_config._push_to_contentgrid(self, record)
3637

3738
@api.model_create_multi
@@ -51,14 +52,6 @@ def _to_store(self, store: Store, **kwargs):
5152

5253
def get_contentgrid_data(self):
5354
self.ensure_one()
54-
result = []
55-
for contentgrid_record in self.contentgrid_ids:
56-
record_data = {
57-
"res_model": contentgrid_record.res_model,
58-
"res_id": contentgrid_record.res_id,
59-
"name": contentgrid_record.name,
60-
}
61-
result.append(record_data)
6255
return [
6356
record._get_contentgrid_data() for record in self.contentgrid_ids.sudo()
6457
]

contentgrid/models/mail_thread.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright 2025 Dixmit
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
from odoo.tools.safe_eval import safe_eval
6+
7+
from odoo.addons.mail.tools.discuss import Store
8+
9+
10+
class MailThread(models.AbstractModel):
11+
_inherit = "mail.thread"
12+
13+
contentgrid_record_ids = fields.One2many(
14+
"contentgrid.record",
15+
"res_id",
16+
domain=lambda self: [("res_model", "=", self._name)],
17+
)
18+
19+
def _thread_to_store(self, store: Store, /, *, request_list=None, **kwargs):
20+
result = super()._thread_to_store(store, request_list=request_list, **kwargs)
21+
contentgrid_config = (
22+
self.env["contentgrid.configuration"]
23+
.search(
24+
[
25+
("model_id.model", "=", self._name),
26+
("active", "=", True),
27+
("allow_manual_send", "=", True),
28+
],
29+
)
30+
.filtered(lambda r: self.filtered_domain(safe_eval(r.domain)))
31+
)
32+
store.add(
33+
self,
34+
{
35+
"contentgrid": bool(self.contentgrid_record_ids),
36+
"sendContentGrid": bool(contentgrid_config),
37+
},
38+
as_thread=True,
39+
)
40+
return result
41+
42+
def get_contentgrid_data(self):
43+
self.ensure_one()
44+
return [
45+
record._get_contentgrid_data()
46+
for record in self.contentgrid_record_ids.sudo()
47+
]
48+
49+
def send_contentgrid_data(self):
50+
self.ensure_one()
51+
self.attachment_ids._push_to_contentgrid(manual_send=True)

contentgrid/readme/USAGE.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ All integrated documents will have the contentgrid icon on the attachment:
77
If you press the icon, a popup will be launched showing the information of it in contentgrid and a link to the app:
88

99
![ContentGrid Popup](../static/img/contentgrid_popup.png)
10+
11+
Also, related records will show the same icon in the thread menu and will allow us to check the data sent to ContentGrid.
12+
13+
![ContentGrid Thread](../static/img/contentgrid_thread.png)
14+
15+
In case we want to force the send, we can do it manually by using the *Allow manual send* field on the configuration.
16+
This will show a button that sends the data to content grid (only attachments not sent)
17+
18+
![ContentGrid Thread](../static/img/contentgrid_thread_force.png)
45.9 KB
Loading

contentgrid/static/description/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,13 @@ <h1><a class="toc-backref" href="#toc-entry-3">Usage</a></h1>
486486
<p>If you press the icon, a popup will be launched showing the information
487487
of it in contentgrid and a link to the app:</p>
488488
<p><img alt="ContentGrid Popup" src="https://raw.githubusercontent.com/dixmit/contentgrid/18.0/contentgrid/static/img/contentgrid_popup.png" /></p>
489+
<p>Also, related records will show the same icon in the thread menu and
490+
will allow us to check the data sent to ContentGrid.</p>
491+
<p><img alt="ContentGrid Thread" src="https://raw.githubusercontent.com/dixmit/contentgrid/18.0/contentgrid/static/img/contentgrid_thread.png" /></p>
492+
<p>In case we want to force the send, we can do it manually by using the
493+
<em>Allow manual send</em> field on the configuration. This will show a button
494+
that sends the data to content grid (only attachments not sent)</p>
495+
<p><img alt="image1" src="https://raw.githubusercontent.com/dixmit/contentgrid/18.0/contentgrid/static/img/contentgrid_thread_force.png" /></p>
489496
</div>
490497
<div class="section" id="bug-tracker">
491498
<h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
21.5 KB
Loading
24.5 KB
Loading

0 commit comments

Comments
 (0)