mirror of https://github.com/muk-it/muk_base
Mathias Markl
6 years ago
31 changed files with 366 additions and 160 deletions
-
2muk_attachment_lobject/__manifest__.py
-
2muk_attachment_lobject/models/ir_attachment.py
-
2muk_converter/__manifest__.py
-
2muk_converter/models/store.py
-
2muk_converter/wizards/convert.py
-
5muk_fields_lobject/__init__.py
-
6muk_fields_lobject/__manifest__.py
-
23muk_fields_lobject/base/__init__.py
-
24muk_fields_lobject/base/fields.py
-
16muk_fields_lobject/base/models.py
-
5muk_fields_lobject/doc/changelog.rst
-
23muk_fields_lobject/fields/__init__.py
-
204muk_fields_lobject/fields/lobject.py
-
2muk_fields_lobject/models/__init__.py
-
2muk_fields_lobject/static/description/index.html
-
2muk_fields_lobject/tests/test_lobject.py
-
3muk_models_groupby_hour/README.md
-
5muk_models_groupby_hour/__init__.py
-
15muk_models_groupby_hour/__manifest__.py
-
22muk_models_groupby_hour/base/__init__.py
-
18muk_models_groupby_hour/base/models.py
-
5muk_models_groupby_hour/doc/changelog.rst
-
46muk_models_groupby_hour/doc/index.rst
-
33muk_models_groupby_hour/static/description/index.html
-
2muk_models_groupby_hour/tests/__init__.py
-
2muk_models_groupby_hour/tests/test_groupby.py
-
6muk_utils/__init__.py
-
3muk_utils/__manifest__.py
-
1muk_utils/tools/__init__.py
-
0muk_utils/tools/http.py
-
43muk_utils/tools/patch.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 |
@ -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 |
@ -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 |
@ -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 '' |
@ -1,3 +0,0 @@ |
|||||
# MuK Groupby Hour |
|
||||
|
|
||||
Allow records to be grouped by hour. |
|
@ -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 |
@ -1,3 +1,8 @@ |
|||||
|
`2.0.0` |
||||
|
------- |
||||
|
|
||||
|
- Migrated to Python 3 |
||||
|
|
||||
`1.0.0` |
`1.0.0` |
||||
------- |
------- |
||||
|
|
||||
|
@ -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). |
@ -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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue