diff --git a/muk_utils/__init__.py b/muk_utils/__init__.py index bc7fee1..5b5d62d 100644 --- a/muk_utils/__init__.py +++ b/muk_utils/__init__.py @@ -17,3 +17,5 @@ # ################################################################################### +from . import models +from . import tools \ No newline at end of file diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index 8ae8c5b..c2cc6df 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -20,7 +20,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '12.0.1.0.17', + "version": '12.0.1.0.18', "category": 'Extra Tools', "license": "AGPL-3", "author": "MuK IT", @@ -30,9 +30,10 @@ "Mathias Markl ", ], "depends": [ - "base", + "base_setup", ], "data": [ + "views/res_config_settings_view.xml", ], "qweb": [ "static/src/xml/*.xml", diff --git a/muk_utils/models/__init__.py b/muk_utils/models/__init__.py new file mode 100644 index 0000000..5d586a5 --- /dev/null +++ b/muk_utils/models/__init__.py @@ -0,0 +1,22 @@ +################################################################################### +# +# Copyright (C) 2018 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 . +# +################################################################################### + +from . import ir_attachment +from . import res_config_settings + diff --git a/muk_utils/models/ir_attachment.py b/muk_utils/models/ir_attachment.py new file mode 100644 index 0000000..bd7e2c9 --- /dev/null +++ b/muk_utils/models/ir_attachment.py @@ -0,0 +1,62 @@ +################################################################################### +# +# Copyright (C) 2018 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 base64 +import logging +import mimetypes + +from odoo import api, models, _ +from odoo.exceptions import AccessError + +_logger = logging.getLogger(__name__) + +class Attachment(models.Model): + + _inherit = 'ir.attachment' + + #---------------------------------------------------------- + # Functions + #---------------------------------------------------------- + + @api.model + def storage_locations(self): + return ['db', 'file'] + + @api.model + def force_storage(self): + if not self.env.user._is_admin(): + raise AccessError(_('Only administrators can execute this action.')) + storage_domain = { + 'db': ('db_datas', '=', False), + 'file': ('store_fname', '=', False), + } + record_domain = [ + '&', storage_domain[self._storage()], + '|', ('res_field', '=', False), ('res_field', '!=', False) + ] + self.search(record_domain).migrate() + return True + + @api.multi + def migrate(self): + record_count = len(self) + storage = self._storage().upper() + for index, attach in enumerate(self): + _logger.info(_("Migrate Attachment %s of %s to %s") % (index + 1, record_count, storage)) + attach.write({'datas': attach.datas}) diff --git a/muk_utils/models/res_config_settings.py b/muk_utils/models/res_config_settings.py new file mode 100644 index 0000000..2775f18 --- /dev/null +++ b/muk_utils/models/res_config_settings.py @@ -0,0 +1,64 @@ +################################################################################### +# +# 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 . +# +################################################################################### + +from odoo import api, fields, models + +class ResConfigSettings(models.TransientModel): + + _inherit = 'res.config.settings' + + #---------------------------------------------------------- + # Selections + #---------------------------------------------------------- + + def _attachment_location_selection(self): + locations = self.env['ir.attachment'].storage_locations() + return list(map(lambda location: (location, location.upper()), locations)) + + #---------------------------------------------------------- + # Database + #---------------------------------------------------------- + + attachment_location = fields.Selection( + selection=_attachment_location_selection, + string='Storage Location', + required=True, + help="Attachment storage location.") + + #---------------------------------------------------------- + # Functions + #---------------------------------------------------------- + + @api.multi + def set_values(self): + res = super(ResConfigSettings, self).set_values() + param = self.env['ir.config_parameter'].sudo() + param.set_param('ir_attachment.location', self.attachment_location) + return res + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + params = self.env['ir.config_parameter'].sudo() + res.update(attachment_location=params.get_param('ir_attachment.location', 'file')) + return res + + @api.multi + def attachment_force_storage(self): + self.env['ir.attachment'].force_storage() \ No newline at end of file diff --git a/muk_utils/views/res_config_settings_view.xml b/muk_utils/views/res_config_settings_view.xml new file mode 100644 index 0000000..cf524a8 --- /dev/null +++ b/muk_utils/views/res_config_settings_view.xml @@ -0,0 +1,53 @@ + + + + + + + + res.config.settings.view.form + res.config.settings + + +
+

Storage

+
+
+
+
+
+
+
+
+
+
+ +
\ No newline at end of file