diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py
index 6da74ea..3a02d96 100644
--- a/muk_utils/__manifest__.py
+++ b/muk_utils/__manifest__.py
@@ -19,7 +19,7 @@
{
"name": "MuK Utils",
"summary": """Utility Features""",
- "version": '12.0.1.5.0',
+ "version": '12.0.1.6.3',
"category": 'Extra Tools',
"license": "AGPL-3",
"author": "MuK IT",
@@ -33,8 +33,9 @@
],
"data": [
"actions/ir_attachment.xml",
+ "views/ir_attachment.xml",
"views/mixins_groups.xml",
- "views/res_config_settings_view.xml",
+ "views/res_config_settings.xml",
],
"qweb": [
"static/src/xml/*.xml",
@@ -46,6 +47,7 @@
"python": [],
"bin": [],
},
+ "sequence": 3,
"application": False,
"installable": True,
"auto_install": False,
diff --git a/muk_utils/doc/changelog.rst b/muk_utils/doc/changelog.rst
index 8d1e28d..fcc9635 100644
--- a/muk_utils/doc/changelog.rst
+++ b/muk_utils/doc/changelog.rst
@@ -1,3 +1,8 @@
+`1.6.0`
+-------
+
+- Override Attachment to make it more extendable
+
`1.5.0`
-------
diff --git a/muk_utils/models/ir_attachment.py b/muk_utils/models/ir_attachment.py
index 9ff4c1a..bf0db19 100644
--- a/muk_utils/models/ir_attachment.py
+++ b/muk_utils/models/ir_attachment.py
@@ -50,6 +50,18 @@ class IrAttachment(models.Model):
'index_content': self._index(bin_data, attach.datas_fname, attach.mimetype),
})
return vals
+
+ @api.model
+ def _get_datas_clean_vals(self, attach):
+ vals = {}
+ if attach.store_fname:
+ vals['store_fname'] = attach.store_fname
+ return vals
+
+ @api.model
+ def _clean_datas_after_write(self, vals):
+ if 'store_fname' in vals:
+ self._file_delete(vals['store_fname'])
#----------------------------------------------------------
# Actions
@@ -76,6 +88,7 @@ class IrAttachment(models.Model):
'file': ('store_fname', '=', False),
}
record_domain = [
+ '&', ('type', '=', 'binary'),
'&', storage_domain[self._storage()],
'|', ('res_field', '=', False), ('res_field', '!=', False)
]
@@ -94,6 +107,7 @@ class IrAttachment(models.Model):
# Read
#----------------------------------------------------------
+ @api.multi
def _compute_mimetype(self, values):
if self.env.context.get('migration') and len(self) == 1:
return self.mimetype or 'application/octet-stream'
@@ -104,6 +118,7 @@ class IrAttachment(models.Model):
# Create, Write, Delete
#----------------------------------------------------------
+ @api.multi
def _inverse_datas(self):
location = self._storage()
for attach in self:
@@ -115,8 +130,7 @@ class IrAttachment(models.Model):
vals['store_fname'] = self._file_write(value, vals['checksum'])
else:
vals['db_datas'] = value
- fname = attach.store_fname
+ clean_vals = self._get_datas_clean_vals(attach)
super(IrAttachment, attach.sudo()).write(vals)
- if fname:
- self._file_delete(fname)
+ self._clean_datas_after_write(clean_vals)
\ No newline at end of file
diff --git a/muk_utils/models/res_config_settings.py b/muk_utils/models/res_config_settings.py
index 5a1c911..5a3bf86 100644
--- a/muk_utils/models/res_config_settings.py
+++ b/muk_utils/models/res_config_settings.py
@@ -36,7 +36,7 @@ class ResConfigSettings(models.TransientModel):
#----------------------------------------------------------
attachment_location = fields.Selection(
- selection=_attachment_location_selection,
+ selection=lambda self: self._attachment_location_selection(),
string='Storage Location',
required=True,
help="Attachment storage location.")
diff --git a/muk_utils/tests/test_attachment_migration.py b/muk_utils/tests/test_attachment_migration.py
new file mode 100644
index 0000000..3410ccd
--- /dev/null
+++ b/muk_utils/tests/test_attachment_migration.py
@@ -0,0 +1,48 @@
+###################################################################################
+#
+# Copyright (C) 2017 MuK IT GmbH
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+#
+###################################################################################
+
+import os
+import base64
+import logging
+
+from odoo import exceptions
+from odoo.tests import common
+
+_path = os.path.dirname(os.path.dirname(__file__))
+_logger = logging.getLogger(__name__)
+
+class MigrationTestCase(common.TransactionCase):
+
+ def setUp(self):
+ super(MigrationTestCase, self).setUp()
+ self.model = self.env['ir.attachment']
+ self.params = env['ir.config_parameter'].sudo()
+ self.location = self.params.get_param('ir_attachment.location')
+ if self.location == 'file':
+ self.params.set_param('ir_attachment.location', 'db')
+ else:
+ self.params.set_param('ir_attachment.location', 'file')
+
+ def tearDown(self):
+ self.params.set_param('ir_attachment.location', self.location)
+ super(MigrationTestCase, self).tearDown()
+
+ def test_migration(self):
+ self.model.search([], limit=5).action_migrate()
+
\ No newline at end of file
diff --git a/muk_utils/tests/test_search_parents.py b/muk_utils/tests/test_search_parents.py
index 39a88c3..3d4fed0 100644
--- a/muk_utils/tests/test_search_parents.py
+++ b/muk_utils/tests/test_search_parents.py
@@ -27,14 +27,14 @@ from odoo.tests import common
_path = os.path.dirname(os.path.dirname(__file__))
_logger = logging.getLogger(__name__)
-class AccessGroupsTestCase(common.TransactionCase):
+class SearchParentTestCase(common.TransactionCase):
def setUp(self):
- super(AccessGroupsTestCase, self).setUp()
+ super(SearchParentTestCase, self).setUp()
self.model = self.env['res.partner.category']
def tearDown(self):
- super(AccessGroupsTestCase, self).tearDown()
+ super(SearchParentTestCase, self).tearDown()
def _evaluate_parent_result(self, parents, records):
for parent in parents:
diff --git a/muk_utils/views/ir_attachment.xml b/muk_utils/views/ir_attachment.xml
new file mode 100644
index 0000000..c259a05
--- /dev/null
+++ b/muk_utils/views/ir_attachment.xml
@@ -0,0 +1,67 @@
+
+
+
+
+
+
+
+ ir_attachment.search
+ ir.attachment
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ir_attachment.tree
+ ir.attachment
+
+
+
+
+
+
+
+
+
+ ir_attachment.form
+ ir.attachment
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/muk_utils/views/res_config_settings_view.xml b/muk_utils/views/res_config_settings.xml
similarity index 100%
rename from muk_utils/views/res_config_settings_view.xml
rename to muk_utils/views/res_config_settings.xml