Browse Source

publish muk_utils - 12.0

pull/9/head
MuK IT GmbH 5 years ago
parent
commit
562ab36170
  1. 6
      muk_utils/__manifest__.py
  2. 5
      muk_utils/doc/changelog.rst
  3. 20
      muk_utils/models/ir_attachment.py
  4. 2
      muk_utils/models/res_config_settings.py
  5. 48
      muk_utils/tests/test_attachment_migration.py
  6. 6
      muk_utils/tests/test_search_parents.py
  7. 67
      muk_utils/views/ir_attachment.xml
  8. 0
      muk_utils/views/res_config_settings.xml

6
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,

5
muk_utils/doc/changelog.rst

@ -1,3 +1,8 @@
`1.6.0`
-------
- Override Attachment to make it more extendable
`1.5.0`
-------

20
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)

2
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.")

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

6
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:

67
muk_utils/views/ir_attachment.xml

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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/>.
-->
<odoo>
<record id="view_attachment_search" model="ir.ui.view">
<field name="name">ir_attachment.search</field>
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="base.view_attachment_search"/>
<field name="arch" type="xml">
<xpath expr="//filter[@name='url_filter']" position="before">
<separator/>
<filter name="all" string="All Data" domain="['|',('res_field', '=', False),('res_field', '!=', False)]"/>
<filter name="set_res_field" string="Field Data" domain="[('res_field', '!=', False)]"/>
<filter name="no_res_field" string="Attachments" domain="[('res_field', '=', False)]"/>
<separator/>
</xpath>
<xpath expr="//group//filter[last()]" position="before">
<separator/>
<filter name="group_res_model" string="Attached Document Model" context="{'group_by': 'res_model'}" />
<filter name="group_res_field" string="Attached Document Field" context="{'group_by': 'res_field'}" />
</xpath>
</field>
</record>
<record id="view_attachment_tree" model="ir.ui.view">
<field name="name">ir_attachment.tree</field>
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="base.view_attachment_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='datas_fname']" position="after">
<field name="mimetype" />
</xpath>
</field>
</record>
<record id="view_attachment_form" model="ir.ui.view">
<field name="name">ir_attachment.form</field>
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="base.view_attachment_form"/>
<field name="arch" type="xml">
<xpath expr="//group[@name='description_group']" position="before">
<group string="Storage" name="storage" groups="base.group_no_one">
<field name="db_datas" readonly="1" attrs="{'invisible':[('db_datas','=',False)]}"/>
<field name="store_fname" readonly="1" attrs="{'invisible':[('store_fname','=',False)]}"/>
</group>
</xpath>
</field>
</record>
</odoo>

0
muk_utils/views/res_config_settings_view.xml → muk_utils/views/res_config_settings.xml

Loading…
Cancel
Save