Holger Brunn
9 years ago
8 changed files with 0 additions and 217 deletions
-
22base_field_serialized/__init__.py
-
35base_field_serialized/__openerp__.py
-
33base_field_serialized/base_field_serialized.py
-
53base_field_serialized/fields.py
-
1base_field_serialized/security/ir.model.access.csv
-
BINbase_field_serialized/static/description/icon.png
-
21base_field_serialized/tests/__init__.py
-
52base_field_serialized/tests/test_serialized.py
@ -1,22 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|
||||
# |
|
||||
# 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 base_field_serialized |
|
@ -1,35 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|
||||
# |
|
||||
# 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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
{ |
|
||||
"name": "Serialized fields", |
|
||||
"version": "8.0.1.0.0", |
|
||||
"author": "Therp BV,Odoo Community Association (OCA)", |
|
||||
"license": "AGPL-3", |
|
||||
"description": """This addon restores serialized fields for Odoo 8.0 |
|
||||
""", |
|
||||
"category": "Hidden/Dependency", |
|
||||
"depends": [ |
|
||||
'base', |
|
||||
], |
|
||||
"auto_install": False, |
|
||||
"installable": True, |
|
||||
"application": False, |
|
||||
} |
|
@ -1,33 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|
||||
# |
|
||||
# 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 openerp import fields |
|
||||
|
|
||||
|
|
||||
class Serialized(fields.Field): |
|
||||
type = 'serialized' |
|
||||
|
|
||||
def convert_to_cache(self, value, env, validate=True): |
|
||||
if value: |
|
||||
return value |
|
||||
else: |
|
||||
return {} |
|
||||
|
|
||||
fields.Serialized = Serialized |
|
@ -1,53 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). |
|
||||
# |
|
||||
# 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 simplejson |
|
||||
import openerp |
|
||||
from openerp.models import FIELDS_TO_PGTYPES |
|
||||
from openerp.osv.fields import _column |
|
||||
|
|
||||
# --------------------------------------------------------- |
|
||||
# Serialized fields |
|
||||
# --------------------------------------------------------- |
|
||||
|
|
||||
|
|
||||
class serialized(_column): |
|
||||
""" A field able to store an arbitrary python data structure. |
|
||||
|
|
||||
Note: only plain components allowed. |
|
||||
""" |
|
||||
|
|
||||
def _symbol_set_struct(val): |
|
||||
return simplejson.dumps(val) |
|
||||
|
|
||||
def _symbol_get_struct(self, val): |
|
||||
return simplejson.loads(val or '{}') |
|
||||
|
|
||||
_prefetch = False |
|
||||
_type = 'serialized' |
|
||||
|
|
||||
_symbol_c = '%s' |
|
||||
_symbol_f = _symbol_set_struct |
|
||||
_symbol_set = (_symbol_c, _symbol_f) |
|
||||
_symbol_get = _symbol_get_struct |
|
||||
|
|
||||
openerp.osv.fields.serialized = serialized |
|
||||
FIELDS_TO_PGTYPES[openerp.osv.fields.serialized] = 'text' |
|
@ -1 +0,0 @@ |
|||||
access_base_field_serialized_test_model,access_base_field_serialized_test_model,model_base_field_serialized_test_model,base.group_no_one,1,1,1,1 |
|
Before Width: 128 | Height: 128 | Size: 16 KiB |
@ -1,21 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|
||||
# |
|
||||
# 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 test_serialized |
|
@ -1,52 +0,0 @@ |
|||||
# -*- coding: utf-8 -*- |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright (C) 2014 Therp BV (<http://therp.nl>). |
|
||||
# |
|
||||
# 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 openerp import models, fields |
|
||||
from openerp.tests.common import TransactionCase |
|
||||
|
|
||||
|
|
||||
class BaseFieldSerializedTestModel(models.Model): |
|
||||
_name = 'base.field.serialized.test.model' |
|
||||
|
|
||||
serialized = fields.Serialized('Serialized') |
|
||||
|
|
||||
|
|
||||
class TestBaseFieldSerialized(TransactionCase): |
|
||||
def test_ReadWrite(self): |
|
||||
BaseFieldSerializedTestModel._build_model(self.registry, self.cr) |
|
||||
testmodel = self.env['base.field.serialized.test.model'] |
|
||||
testmodel._prepare_setup() |
|
||||
testmodel._setup_base(False) |
|
||||
testmodel._setup_fields() |
|
||||
testmodel._setup_complete() |
|
||||
testmodel._auto_init() |
|
||||
record = testmodel.create( |
|
||||
{'serialized': ['hello world']}) |
|
||||
self.assertEqual(record.serialized, ['hello world']) |
|
||||
self.env.invalidate_all() |
|
||||
self.assertEqual(record.serialized, ['hello world']) |
|
||||
record.write({'serialized': {'hello': 'world'}}) |
|
||||
self.env.invalidate_all() |
|
||||
self.assertEqual(record.serialized, {'hello': 'world'}) |
|
||||
record.write({'serialized': None}) |
|
||||
self.assertEqual( |
|
||||
self.registry['base.field.serialized.test.model'].browse( |
|
||||
self.cr, self.uid, record.id).serialized, |
|
||||
{}) |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue