Browse Source

..

pull/6/head
Mathias Markl 7 years ago
parent
commit
ef14d698a3
  1. 2
      muk_attachment_lobject/__manifest__.py
  2. 2
      muk_attachment_lobject/models/ir_attachment.py
  3. 2
      muk_converter/__manifest__.py
  4. 2
      muk_converter/models/store.py
  5. 2
      muk_converter/wizards/convert.py
  6. 5
      muk_fields_lobject/__init__.py
  7. 6
      muk_fields_lobject/__manifest__.py
  8. 23
      muk_fields_lobject/base/__init__.py
  9. 24
      muk_fields_lobject/base/fields.py
  10. 16
      muk_fields_lobject/base/models.py
  11. 5
      muk_fields_lobject/doc/changelog.rst
  12. 23
      muk_fields_lobject/fields/__init__.py
  13. 204
      muk_fields_lobject/fields/lobject.py
  14. 2
      muk_fields_lobject/models/__init__.py
  15. 2
      muk_fields_lobject/static/description/index.html
  16. 2
      muk_fields_lobject/tests/test_lobject.py
  17. 3
      muk_models_groupby_hour/README.md
  18. 5
      muk_models_groupby_hour/__init__.py
  19. 15
      muk_models_groupby_hour/__manifest__.py
  20. 22
      muk_models_groupby_hour/base/__init__.py
  21. 18
      muk_models_groupby_hour/base/models.py
  22. 5
      muk_models_groupby_hour/doc/changelog.rst
  23. 46
      muk_models_groupby_hour/doc/index.rst
  24. 33
      muk_models_groupby_hour/static/description/index.html
  25. 2
      muk_models_groupby_hour/tests/__init__.py
  26. 2
      muk_models_groupby_hour/tests/test_groupby.py
  27. 6
      muk_utils/__init__.py
  28. 3
      muk_utils/__manifest__.py
  29. 1
      muk_utils/tools/__init__.py
  30. 0
      muk_utils/tools/http.py
  31. 43
      muk_utils/tools/patch.py

2
muk_attachment_lobject/__manifest__.py

@ -22,7 +22,7 @@
{
"name": "MuK Large Objects Attachment",
"summary": """Large Objects Attachment Location""",
"version": '11.0.2.0.0',
"version": '11.0.2.0.1',
"category": 'Extra Tools',
"license": "AGPL-3",
"website": "http://www.mukit.at",

2
muk_attachment_lobject/models/ir_attachment.py

@ -26,7 +26,7 @@ import mimetypes
from odoo import api, models, _
from odoo.exceptions import AccessError
from odoo.addons.muk_fields_lobject.fields import LargeObject
from odoo.addons.muk_fields_lobject.fields.lobject import LargeObject
_logger = logging.getLogger(__name__)

2
muk_converter/__manifest__.py

@ -20,7 +20,7 @@
{
"name": "MuK Converter",
"summary": """Universal Converter""",
"version": '11.0.1.1.3',
"version": '11.0.1.1.4',
"category": 'Extra Tools',
"license": "AGPL-3",
"website": "https://www.mukit.at",

2
muk_converter/models/store.py

@ -21,7 +21,7 @@ import logging
from odoo import api, models, fields
from odoo.addons.muk_fields_lobject.fields import LargeObject
from odoo.addons.muk_fields_lobject.fields.lobject import LargeObject
_logger = logging.getLogger(__name__)

2
muk_converter/wizards/convert.py

@ -25,7 +25,7 @@ import mimetypes
from odoo import _, api, fields, models
from odoo.addons.muk_utils.http import get_response
from odoo.addons.muk_utils.tools.http import get_response
from odoo.addons.muk_converter.tools import converter
_logger = logging.getLogger(__name__)

5
muk_fields_lobject/__init__.py

@ -19,4 +19,7 @@
from . import fields
from . import models
from . import controllers
from . import controllers
def _patch_system():
from . import base

6
muk_fields_lobject/__manifest__.py

@ -20,7 +20,7 @@
{
"name": "MuK Large Objects",
"summary": """PGSQL Large Objects Support""",
"version": '11.0.2.1.0',
"version": '11.0.2.2.0',
"category": 'Extra Tools',
"license": "AGPL-3",
"website": "https://www.mukit.at",
@ -42,8 +42,8 @@
"python": [],
"bin": [],
},
"auto_install": True,
"auto_install": False,
"application": False,
"installable": True,
"post_load": "_patch_system",
}

23
muk_fields_lobject/base/__init__.py

@ -0,0 +1,23 @@
###################################################################################
#
# MuK Document Management System
#
# 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 fields
from . import models

24
muk_fields_lobject/base/fields.py

@ -0,0 +1,24 @@
###################################################################################
#
# 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 odoo import fields
from odoo.addons.muk_fields_lobject.fields.lobject import LargeObject
fields.LargeObject = LargeObject

16
muk_fields_lobject/models.py → muk_fields_lobject/base/models.py

@ -19,13 +19,15 @@
import logging
from odoo import models
from odoo import models, api
_logger = logging.getLogger(__name__)
from odoo.addons.muk_utils.tools import patch
unlink = models.BaseModel.unlink
_logger = logging.getLogger(__name__)
def large_object_unlink(self):
@api.multi
@patch.monkey_patch_model(models.BaseModel)
def unlink(self):
oids = []
for name in self._fields:
field = self._fields[name]
@ -34,8 +36,6 @@ def large_object_unlink(self):
oid = record.with_context({'oid': True})[name]
if oid:
oids.append(oid)
unlink(self)
unlink.super(self)
for oid in oids:
self.env.cr._cnx.lobject(oid, 'rb').unlink()
models.BaseModel.unlink = large_object_unlink
self.env.cr._cnx.lobject(oid, 'rb').unlink()

5
muk_fields_lobject/doc/changelog.rst

@ -1,3 +1,8 @@
`2.2.0`
-------
- Monkey Patch Methods
`2.1.0`
-------

23
muk_fields_lobject/fields/__init__.py

@ -0,0 +1,23 @@
###################################################################################
#
# 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 lobject
# backward compatibility
from .lobject import LargeObject

204
muk_fields_lobject/fields.py → muk_fields_lobject/fields/lobject.py

@ -1,103 +1,101 @@
###################################################################################
#
# 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 hashlib
import logging
import binascii
import tempfile
from odoo import fields
from odoo.tools import human_size
_logger = logging.getLogger(__name__)
class LargeObject(fields.Field):
type = 'lobject'
column_type = ('oid', 'oid')
_slots = {
'prefetch': False,
'context_dependent': True,
}
def convert_to_column(self, value, record, values=None):
oid = record.with_context({'oid': True})[self.name]
if oid:
record.env.cr._cnx.lobject(oid, 'rb').unlink()
if not value:
return None
lobject = record.env.cr._cnx.lobject(0, 'wb')
if isinstance(value, bytes):
try:
if base64.b64encode(base64.b64decode(value)) == value:
lobject.write(base64.b64decode(value))
else:
lobject.write(value)
except binascii.Error:
lobject.write(value)
elif isinstance(value, str):
lobject.write(base64.b64decode(value.encode('ascii')))
else:
while True:
chunk = value.read(4096)
if not chunk:
break
lobject.write(chunk)
return lobject.oid
def convert_to_record(self, value, record):
if value and isinstance(value, int):
lobject = record.env.cr._cnx.lobject(value, 'rb')
if record._context.get('human_size'):
return human_size(lobject.seek(0, 2))
elif record._context.get('bin_size'):
return lobject.seek(0, 2)
elif record._context.get('oid'):
return lobject.oid
elif record._context.get('base64'):
return base64.b64encode(lobject.read())
elif record._context.get('stream'):
file = tempfile.TemporaryFile()
while True:
chunk = lobject.read(4096)
if not chunk:
file.seek(0)
return file
file.write(chunk)
elif record._context.get('checksum'):
checksum = hashlib.md5()
while True:
chunk = lobject.read(4096)
if not chunk:
return checksum.hexdigest()
checksum.update(chunk)
else:
return lobject.read()
return value
def convert_to_export(self, value, record):
if value:
lobject = record.env.cr._cnx.lobject(value, 'rb')
if record._context.get('export_raw_data'):
return lobject.read()
return base64.b64encode(lobject.read())
return ''
fields.LargeObject = LargeObject
###################################################################################
#
# 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 hashlib
import logging
import binascii
import tempfile
from odoo import fields
from odoo.tools import human_size
_logger = logging.getLogger(__name__)
class LargeObject(fields.Field):
type = 'lobject'
column_type = ('oid', 'oid')
_slots = {
'prefetch': False,
'context_dependent': True,
}
def convert_to_column(self, value, record, values=None):
oid = record.with_context({'oid': True})[self.name]
if oid:
record.env.cr._cnx.lobject(oid, 'rb').unlink()
if not value:
return None
lobject = record.env.cr._cnx.lobject(0, 'wb')
if isinstance(value, bytes):
try:
if base64.b64encode(base64.b64decode(value)) == value:
lobject.write(base64.b64decode(value))
else:
lobject.write(value)
except binascii.Error:
lobject.write(value)
elif isinstance(value, str):
lobject.write(base64.b64decode(value.encode('ascii')))
else:
while True:
chunk = value.read(4096)
if not chunk:
break
lobject.write(chunk)
return lobject.oid
def convert_to_record(self, value, record):
if value and isinstance(value, int):
lobject = record.env.cr._cnx.lobject(value, 'rb')
if record._context.get('human_size'):
return human_size(lobject.seek(0, 2))
elif record._context.get('bin_size'):
return lobject.seek(0, 2)
elif record._context.get('oid'):
return lobject.oid
elif record._context.get('base64'):
return base64.b64encode(lobject.read())
elif record._context.get('stream'):
file = tempfile.TemporaryFile()
while True:
chunk = lobject.read(4096)
if not chunk:
file.seek(0)
return file
file.write(chunk)
elif record._context.get('checksum'):
checksum = hashlib.md5()
while True:
chunk = lobject.read(4096)
if not chunk:
return checksum.hexdigest()
checksum.update(chunk)
else:
return lobject.read()
return value
def convert_to_export(self, value, record):
if value:
lobject = record.env.cr._cnx.lobject(value, 'rb')
if record._context.get('export_raw_data'):
return lobject.read()
return base64.b64encode(lobject.read())
return ''

2
muk_fields_lobject/models/__init__.py

@ -1,4 +1,4 @@
###################################################################################
###################################################################################
#
# Copyright (C) 2018 MuK IT GmbH
#

2
muk_fields_lobject/static/description/index.html

@ -55,7 +55,7 @@
<pre>
<code>
from odoo.addons.muk_fields_lobject.fields import LargeObject
from odoo.addons.muk_fields_lobject.fields.lobject import LargeObject
class LargeObjectModel(models.Model):

2
muk_fields_lobject/tests/test_lobject.py

@ -22,7 +22,7 @@ import logging
from odoo.tests import common
from odoo.addons.muk_fields_lobject.fields import LargeObject
from odoo.addons.muk_fields_lobject.fields.lobject import LargeObject
_path = os.path.dirname(os.path.dirname(__file__))
_logger = logging.getLogger(__name__)

3
muk_models_groupby_hour/README.md

@ -1,3 +0,0 @@
# MuK Groupby Hour
Allow records to be grouped by hour.

5
muk_models_groupby_hour/__init__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright (C) 2018 MuK IT GmbH
@ -19,4 +17,5 @@
#
###################################################################################
from . import models
def _patch_system():
from . import base

15
muk_models_groupby_hour/__manifest__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright (C) 2018 MuK IT GmbH
@ -22,10 +20,7 @@
{
"name": "MuK Groupby Hour",
"summary": """Group records by hour""",
"description": """
Allow records to be grouped by hour.
""",
"version": '11.0.1.0.1',
"version": '11.0.2.0.0',
"category": 'Extra Tools',
"license": "AGPL-3",
"website": "http://www.mukit.at",
@ -34,12 +29,10 @@
"Mathias Markl <mathias.markl@mukit.at>",
],
"depends": [
"base",
"muk_utils",
],
"data": [
],
"demo": [
],
"qweb": [
"static/src/xml/*.xml",
],
@ -50,8 +43,8 @@
"python": [],
"bin": [],
},
"auto_install": True,
"auto_install": False,
"application": False,
"installable": True,
"post_load": "_patch_system",
}

22
muk_models_groupby_hour/base/__init__.py

@ -0,0 +1,22 @@
###################################################################################
#
# MuK Document Management System
#
# 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 models

18
muk_models_groupby_hour/models.py → muk_models_groupby_hour/base/models.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Copyright (C) 2018 MuK IT GmbH
@ -30,11 +28,13 @@ from odoo import _
from odoo import models, api, fields
from odoo.tools import ustr, pycompat, human_size
_logger = logging.getLogger(__name__)
_read_group_process_groupby = models.BaseModel._read_group_process_groupby
from odoo.addons.muk_utils.tools import patch
def _read_group_process_groupby_hour(self, gb, query):
_logger = logging.getLogger(__name__)
@api.model
@patch.monkey_patch_model(models.BaseModel)
def _read_group_process_groupby(self, gb, query):
split = gb.split(':')
field_type = self._fields[split[0]].type
gb_function = split[1] if len(split) == 2 else None
@ -56,8 +56,4 @@ def _read_group_process_groupby_hour(self, gb, query):
'tz_convert': tz_convert,
'qualified_field': qualified_field
}
return _read_group_process_groupby(self, gb, query)
models.BaseModel._read_group_process_groupby = _read_group_process_groupby_hour
return _read_group_process_groupby.super(self, gb, query)

5
muk_models_groupby_hour/doc/changelog.rst

@ -1,3 +1,8 @@
`2.0.0`
-------
- Migrated to Python 3
`1.0.0`
-------

46
muk_models_groupby_hour/doc/index.rst

@ -0,0 +1,46 @@
================
MuK Groupby Hour
================
Technical module to provide some utility features to enable group by hour. This
module has no direct effect on the running system.
Installation
============
To install this module, you need to:
Download the module and add it to your Odoo addons folder. Afterward, log on to
your Odoo server and go to the Apps menu. Trigger the debug modus and update the
list by clicking on the "Update Apps List" link. Now install the module by
clicking on the install button.
Configuration
=============
No additional configuration is needed to use this module.
Usage
=============
This module has no direct visible effect on the system. It provide utility features.
Credits
=======
Contributors
------------
* Mathias Markl <mathias.markl@mukit.at>
Author & Maintainer
-------------------
This module is maintained by the `MuK IT GmbH <https://www.mukit.at/>`_.
MuK IT is an Austrian company specialized in customizing and extending Odoo.
We develop custom solutions for your individual needs to help you focus on
your strength and expertise to grow your business.
If you want to get in touch please contact us via mail
(sale@mukit.at) or visit our website (https://mukit.at).

33
muk_models_groupby_hour/static/description/index.html

@ -9,7 +9,7 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<div class="oe_picture">
<div style="max-width: 84%; margin: 16px 8%;">
<h3 class="oe_slogan">Overview</h3>
<div class="oe_mt32"
style="padding-bottom: 10px; text-align: justify;">
@ -37,14 +37,45 @@ def sales_per_hour(self):
</div>
</section>
<section class="oe_container oe_dark"
style="margin-bottom: 20px; border-top: 5px solid #797979; border-bottom: 5px solid #797979;">
<h3 class="oe_slogan" style="margin-bottom: 10px;">Demo</h3>
<div class="row" style="margin: auto; max-width: 200px;">
<div class="col-xs-6">
<h5 class="oe_slogan" style="font-size: 20px; margin: 2px;">User:</h5>
</div>
<div class="col-xs-6">
<h5 class="oe_slogan" style="font-size: 20px; margin: 2px;">apps</h5>
</div>
<div class="col-xs-6">
<h5 class="oe_slogan" style="font-size: 20px; margin: 2px;">Password:</h5>
</div>
<div class="col-xs-6">
<h5 class="oe_slogan" style="font-size: 20px; margin: 2px;">demo</h5>
</div>
</div>
<div class="oe_slogan" style="margin-top: 5px;">
<a class="btn btn-primary btn-lg mt8" href="https://demo.mukit.at/web/login"
style="position: relative; overflow: hidden;"><span
class="o_ripple"
style="height: 138px; width: 138px; top: -35.2969px; left: -8.17188px;"></span>
<i class="fa fa-video-camera"></i> Live Preview </a>
</div>
</section>
<section class="oe_container oe_dark">
<h3 class="oe_slogan">Help and Support</h3>
<h5 class="oe_slogan" style="font-size: 20px;">Feel free to
contact us, if you need any help with your Odoo integration or addiontal
features.</h5>
<div class="oe_slogan">
<a class="btn btn-primary btn-lg mt8" href="mailto:sale@mukit.at">
<i class="fa fa-envelope"></i> Email
</a> <a class="btn btn-primary btn-lg mt8"
href="https://mukit.at/page/contactus"> <i class="fa fa-phone"></i>
Contact
</a> <a class="btn btn-primary btn-lg mt8" href="mailto:support@mukit.at">
<i class="fa fa-life-ring"></i> Support
</a>
</div>
<img src="logo.png" style="width: 200px; margin-bottom: 20px;"

2
muk_models_groupby_hour/tests/__init__.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# MuK Document Management System

2
muk_models_groupby_hour/tests/test_groupby.py

@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# MuK Document Management System

6
muk_utils/__init__.py

@ -17,5 +17,7 @@
#
###################################################################################
from . import http
from . import tools
from . import tools
def _patch_system():
from . import http

3
muk_utils/__manifest__.py

@ -20,7 +20,7 @@
{
"name": "MuK Utils",
"summary": """Utility Features""",
"version": '11.0.1.0.3',
"version": '11.0.1.0.5',
"category": 'Extra Tools',
"license": "AGPL-3",
"website": "https://www.mukit.at",
@ -45,5 +45,4 @@
"auto_install": True,
"application": False,
"installable": True,
}

1
muk_utils/tools/__init__.py

@ -18,5 +18,6 @@
###################################################################################
from . import helper
from . import patch
from . import parse_rst
from . import utils_os

0
muk_utils/http.py → muk_utils/tools/http.py

43
muk_utils/tools/patch.py

@ -0,0 +1,43 @@
###################################################################################
#
# 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 logging
from odoo import api
_logger = logging.getLogger(__name__)
def monkey_patch(cls):
def decorate(func):
name = func.__name__
func.super = getattr(cls, name, None)
setattr(cls, name, func)
return func
return decorate
def monkey_patch_model(cls):
def decorate(func):
name = func.__name__
super = getattr(cls, name, None)
func.super = super
wrapped = api.guess(api.propagate(name, func))
wrapped.super = super
setattr(cls, name, wrapped)
return func
return decorate
Loading…
Cancel
Save