Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 6 years ago
parent
commit
9c56e68fda
  1. 2
      muk_utils/__init__.py
  2. 5
      muk_utils/__manifest__.py
  3. 22
      muk_utils/models/__init__.py
  4. 62
      muk_utils/models/ir_attachment.py
  5. 64
      muk_utils/models/res_config_settings.py
  6. 53
      muk_utils/views/res_config_settings_view.xml

2
muk_utils/__init__.py

@ -17,3 +17,5 @@
#
###################################################################################
from . import models
from . import tools

5
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 <mathias.markl@mukit.at>",
],
"depends": [
"base",
"base_setup",
],
"data": [
"views/res_config_settings_view.xml",
],
"qweb": [
"static/src/xml/*.xml",

22
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 <http://www.gnu.org/licenses/>.
#
###################################################################################
from . import ir_attachment
from . import res_config_settings

62
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 <http://www.gnu.org/licenses/>.
#
###################################################################################
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})

64
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 <http://www.gnu.org/licenses/>.
#
###################################################################################
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()

53
muk_utils/views/res_config_settings_view.xml

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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 <http://www.gnu.org/licenses/>.
-->
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form"/>
<field name="arch" type="xml">
<div name="integration" position="after">
<h2>Storage</h2>
<div class="row mt16 o_settings_container" name="web_client">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane"></div>
<div class="o_setting_right_pane">
<label for="attachment_location"/>
<div class="text-muted">
Attachment storage location.
</div>
<div class="mt8">
<field name="attachment_location"
class="o_light_label"/>
</div>
<div class="mt8">
<button name="attachment_force_storage"
string="Force Storage Migration"
type="object" icon="fa-refresh"/>
</div>
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>
Loading…
Cancel
Save