[MIG] autovacuum_message_attachment : migrate to v16

pull/2766/head
Florian da Costa 2023-11-24 17:41:40 +01:00
parent 8b5b6ecd22
commit 5693420182
7 changed files with 45 additions and 38 deletions

View File

@ -7,7 +7,7 @@ AutoVacuum Mail Message and Attachment
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:624132e2a8eb145234cf3521c94b6fb37a03336dfc7cd23aa236d6e482a3d14b !! source digest: sha256:5d92fc2ff4e6eb045db18185a8bbcd80cdd1cb1cad66ff6a21b3bddfd21b62af
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@ -17,13 +17,13 @@ AutoVacuum Mail Message and Attachment
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3 :alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github
:target: https://github.com/OCA/server-tools/tree/14.0/autovacuum_message_attachment :target: https://github.com/OCA/server-tools/tree/16.0/autovacuum_message_attachment
:alt: OCA/server-tools :alt: OCA/server-tools
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-autovacuum_message_attachment :target: https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-autovacuum_message_attachment
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=14.0 :target: https://runboat.odoo-community.org/builds?repo=OCA/server-tools&target_branch=16.0
:alt: Try me on Runboat :alt: Try me on Runboat
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -60,7 +60,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20autovacuum_message_attachment%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. `feedback <https://github.com/OCA/server-tools/issues/new?body=module:%20autovacuum_message_attachment%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -93,6 +93,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/14.0/autovacuum_message_attachment>`_ project on GitHub. This module is part of the `OCA/server-tools <https://github.com/OCA/server-tools/tree/16.0/autovacuum_message_attachment>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@ -3,7 +3,7 @@
{ {
"name": "AutoVacuum Mail Message and Attachment", "name": "AutoVacuum Mail Message and Attachment",
"version": "14.0.1.0.1", "version": "16.0.1.0.0",
"category": "Tools", "category": "Tools",
"website": "https://github.com/OCA/server-tools", "website": "https://github.com/OCA/server-tools",
"author": "Akretion, Odoo Community Association (OCA)", "author": "Akretion, Odoo Community Association (OCA)",

View File

@ -15,24 +15,23 @@ class AutovacuumMixin(models.AbstractModel):
_description = "Mixin used to delete messages or attachments" _description = "Mixin used to delete messages or attachments"
def batch_unlink(self): def batch_unlink(self):
with api.Environment.manage(): with odoo.registry(self.env.cr.dbname).cursor() as new_cr:
with odoo.registry(self.env.cr.dbname).cursor() as new_cr: new_env = api.Environment(new_cr, self.env.uid, self.env.context)
new_env = api.Environment(new_cr, self.env.uid, self.env.context) try:
try: while self:
while self: batch_delete = self[0:1000]
batch_delete = self[0:1000] self -= batch_delete
self -= batch_delete # do not attach new env to self because it may be
# do not attach new env to self because it may be # huge, and the cache is cleaned after each unlink
# huge, and the cache is cleaned after each unlink # so we do not want to much record is the env in
# so we do not want to much record is the env in # which we call unlink because odoo would prefetch
# which we call unlink because odoo would prefetch # fields, cleared right after.
# fields, cleared right after. batch_delete.with_env(new_env).unlink()
batch_delete.with_env(new_env).unlink() new_env.cr.commit()
new_env.cr.commit() except Exception as e:
except Exception as e: _logger.exception(
_logger.exception( "Failed to delete Ms : {} - {}".format(self._name, str(e))
"Failed to delete Ms : {} - {}".format(self._name, str(e)) )
)
# Call by cron # Call by cron
@api.model @api.model

View File

@ -59,13 +59,14 @@ class VacuumRule(models.Model):
help="Technical field used to set attributes (invisible/required, " help="Technical field used to set attributes (invisible/required, "
"domain, etc...for other fields, like the domain filter", "domain, etc...for other fields, like the domain filter",
) )
model_filter_domain = fields.Text(string="Model Filter Domain") model_filter_domain = fields.Text()
model = fields.Char(readonly=True, compute="_compute_model_id", string="Model code") model = fields.Char(readonly=True, compute="_compute_model_id", string="Model code")
message_type = fields.Selection( message_type = fields.Selection(
[ [
("email", "Email"), ("email", "Email"),
("comment", "Comment"), ("comment", "Comment"),
("notification", "System notification"), ("notification", "System notification"),
("user_notification", "User Specific Notification"),
("all", "All"), ("all", "All"),
] ]
) )

View File

@ -367,9 +367,9 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:624132e2a8eb145234cf3521c94b6fb37a03336dfc7cd23aa236d6e482a3d14b !! source digest: sha256:5d92fc2ff4e6eb045db18185a8bbcd80cdd1cb1cad66ff6a21b3bddfd21b62af
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/14.0/autovacuum_message_attachment"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-autovacuum_message_attachment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p> <p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/16.0/autovacuum_message_attachment"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-16-0/server-tools-16-0-autovacuum_message_attachment"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>Odoo create a lot of message and/or mails. With time it can slow the system or take a lot of disk space. <p>Odoo create a lot of message and/or mails. With time it can slow the system or take a lot of disk space.
The goal of this module is to clean these message once they are obsolete. The goal of this module is to clean these message once they are obsolete.
The same may happen with attachment that we store. The same may happen with attachment that we store.
@ -408,7 +408,7 @@ Odoo will find all attachments containing the substring configured on the rule,
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/server-tools/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20autovacuum_message_attachment%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <a class="reference external" href="https://github.com/OCA/server-tools/issues/new?body=module:%20autovacuum_message_attachment%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -435,7 +435,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/14.0/autovacuum_message_attachment">OCA/server-tools</a> project on GitHub.</p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/server-tools/tree/16.0/autovacuum_message_attachment">OCA/server-tools</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

View File

@ -4,7 +4,7 @@
import base64 import base64
from datetime import date, timedelta from datetime import date, timedelta
from odoo import api, exceptions from odoo import api, exceptions, registry
from odoo.tests import common from odoo.tests import common
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
@ -24,10 +24,10 @@ class TestVacuumRule(common.TransactionCase):
def tearDown(self): def tearDown(self):
self.registry.leave_test_mode() self.registry.leave_test_mode()
super(TestVacuumRule, self).tearDown() super().tearDown()
def setUp(self): def setUp(self):
super(TestVacuumRule, self).setUp() super().setUp()
self.registry.enter_test_mode(self.env.cr) self.registry.enter_test_mode(self.env.cr)
self.env = api.Environment( self.env = api.Environment(
self.registry.test_cr, self.env.uid, self.env.context self.registry.test_cr, self.env.uid, self.env.context
@ -158,8 +158,15 @@ class TestVacuumRule(common.TransactionCase):
rule = self.env["vacuum.rule"].create(rule_vals) rule = self.env["vacuum.rule"].create(rule_vals)
self.message_obj.autovacuum(ttype="message") self.message_obj.autovacuum(ttype="message")
# no message deleted as the filter does not match # no message deleted as the filter does not match
self.assertEqual(len(partner.message_ids), 1) # we need to check the existence of the message in a new cursor because
# it its deleted in batch in separated cursor. The original test's cursor
# is not aware of the deletion otherwise.
with registry(self.env.cr.dbname).cursor() as new_cr:
partner_new_env = partner.with_env(partner.env(cr=new_cr))
self.assertEqual(len(partner_new_env.message_ids), 1)
rule.write({"model_filter_domain": "[['name', '=', 'Test Partner']]"}) rule.write({"model_filter_domain": "[['name', '=', 'Test Partner']]"})
self.message_obj.autovacuum(ttype="message") self.message_obj.autovacuum(ttype="message")
self.assertEqual(len(partner.message_ids), 0) with registry(self.env.cr.dbname).cursor() as new_cr:
partner_new_env = partner.with_env(partner.env(cr=new_cr))
self.assertEqual(len(partner_new_env.message_ids), 0)

View File

@ -34,14 +34,14 @@
string="Message Subtypes" string="Message Subtypes"
attrs="{'invisible': [('ttype', '!=', 'message')]}" attrs="{'invisible': [('ttype', '!=', 'message')]}"
> >
<field name="message_subtype_ids" nolabel="1" /> <field name="message_subtype_ids" nolabel="1" colspan="4" />
</group> </group>
<group attrs="{'invisible': [('ttype', '!=', 'attachment')]}"> <group attrs="{'invisible': [('ttype', '!=', 'attachment')]}">
<field name="filename_pattern" /> <field name="filename_pattern" />
<field name="inheriting_model" /> <field name="inheriting_model" />
</group> </group>
<group string="Message Models"> <group string="Models">
<field name="model_ids" nolabel="1" /> <field name="model_ids" nolabel="1" colspan="4" />
</group> </group>
<group> <group>
<field name="model_id" /> <field name="model_id" />