base_jsonify: cleanups
remove copyrights from init and update copyrightspull/1704/head
parent
c51bb8ca1b
commit
cfabca6d04
|
@ -2,9 +2,9 @@
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
:alt: License: AGPL-3
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
==============
|
============
|
||||||
Base Jsonify
|
Base Jsonify
|
||||||
==============
|
============
|
||||||
|
|
||||||
This module add the jsonify method to the ORM. This method take as argument
|
This module add the jsonify method to the ORM. This method take as argument
|
||||||
the browse record and the "parser" that specify the field to extract.
|
the browse record and the "parser" that specify the field to extract.
|
||||||
|
@ -76,7 +76,7 @@ This is a technical module not function feature is added
|
||||||
Known issues / Roadmap
|
Known issues / Roadmap
|
||||||
======================
|
======================
|
||||||
|
|
||||||
Nothing yet
|
No distinction between float 0.0L and no value
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
@ -98,6 +98,7 @@ Contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* BEAU Sébastien <sebastien.beau@akretion.com>
|
* BEAU Sébastien <sebastien.beau@akretion.com>
|
||||||
|
* Raphaël Reverdy <raphael.reverdy@akretion.com>
|
||||||
* Laurent Mignon <laurent.mignon@acsone.eu>
|
* Laurent Mignon <laurent.mignon@acsone.eu>
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
|
|
|
@ -1,7 +1,2 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2016 Akretion (http://www.akretion.com)
|
|
||||||
# Sébastien BEAU <sebastien.beau@akretion.com>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
||||||
|
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2016 Akretion (http://www.akretion.com)
|
# © 2017 Akretion (http://www.akretion.com)
|
||||||
# Sébastien BEAU <sebastien.beau@akretion.com>
|
# Sébastien BEAU <sebastien.beau@akretion.com>
|
||||||
|
# Raphaël Reverdy <raphael.reverdy@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "Base Jsonify",
|
"name": "Base Jsonify",
|
||||||
"summary": "Base module that provide the jsonify method on all object",
|
"summary": "Base module that provide the jsonify method on all object",
|
||||||
"version": "8.0.1.0.0",
|
"version": "10.0.1.0.0",
|
||||||
"category": "Uncategorized",
|
"category": "Uncategorized",
|
||||||
"website": "https://odoo-community.org/",
|
"website": "https://odoo-community.org/",
|
||||||
"author": "Akretion, Odoo Community Association (OCA)",
|
"author": "Akretion, Odoo Community Association (OCA)",
|
|
@ -1,11 +1,7 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<openerp>
|
<odoo>
|
||||||
<data>
|
<record id="ir_exp_partner" model="ir.exports">
|
||||||
|
|
||||||
<record id="ir_exp_partner" model="ir.exports">
|
|
||||||
<field name="name">Partner Export</field>
|
<field name="name">Partner Export</field>
|
||||||
<field name="resource">res.partner</field>
|
<field name="resource">res.partner</field>
|
||||||
</record>
|
</record>
|
||||||
|
</odoo>
|
||||||
</data>
|
|
||||||
</openerp>
|
|
|
@ -1,9 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2016 Akretion (http://www.akretion.com)
|
|
||||||
# Sébastien BEAU <sebastien.beau@akretion.com>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
||||||
|
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
from . import ir_export
|
from . import ir_export
|
||||||
from . import ir_exports_line
|
from . import ir_exports_line
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2016 Akretion (http://www.akretion.com)
|
# © 2017 Akretion (http://www.akretion.com)
|
||||||
# Sébastien BEAU <sebastien.beau@akretion.com>
|
# Sébastien BEAU <sebastien.beau@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from openerp import api, models
|
from odoo import api, models
|
||||||
|
|
||||||
|
|
||||||
def update_dict(data, fields):
|
def update_dict(data, fields):
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
# Copyright 2017 ACSONE SA/NV
|
# Copyright 2017 ACSONE SA/NV
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from openerp import api, fields, models, _
|
from odoo import api, fields, models, _
|
||||||
|
|
||||||
|
|
||||||
class IrExportsLine(models.Model):
|
class IrExportsLine(models.Model):
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2016 Akretion (http://www.akretion.com)
|
# © 2017 Akretion (http://www.akretion.com)
|
||||||
# Sébastien BEAU <sebastien.beau@akretion.com>
|
# Sébastien BEAU <sebastien.beau@akretion.com>
|
||||||
|
# Raphaël Reverdy <raphael.reverdy@akretion.com>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||||
|
|
||||||
from openerp import api, models
|
from odoo import api, models
|
||||||
from openerp.exceptions import Warning as UserError
|
from odoo.exceptions import UserError
|
||||||
from openerp.tools.translate import _
|
from odoo.tools.translate import _
|
||||||
|
|
||||||
|
|
||||||
def __parse_field(parser_field):
|
class Base(models.AbstractModel):
|
||||||
|
|
||||||
|
_inherit = 'base'
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
def __parse_field(self, parser_field):
|
||||||
field_name = parser_field
|
field_name = parser_field
|
||||||
subparser = None
|
subparser = None
|
||||||
if isinstance(parser_field, tuple):
|
if isinstance(parser_field, tuple):
|
||||||
|
@ -19,8 +25,8 @@ def __parse_field(parser_field):
|
||||||
return field_name, json_key, subparser
|
return field_name, json_key, subparser
|
||||||
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
def jsonify(self, parser):
|
def jsonify(self, parser):
|
||||||
""" Convert the record according to the parser given
|
""" Convert the record according to the parser given
|
||||||
Example of parser:
|
Example of parser:
|
||||||
parser = [
|
parser = [
|
||||||
|
@ -45,15 +51,16 @@ def jsonify(self, parser):
|
||||||
"""
|
"""
|
||||||
result = []
|
result = []
|
||||||
empty_value = {
|
empty_value = {
|
||||||
'char': '',
|
'char': None,
|
||||||
'int': 0,
|
'int': None,
|
||||||
'float': 0,
|
# 'float': None, TODO: 0.0 != False
|
||||||
|
'text': None,
|
||||||
}
|
}
|
||||||
|
|
||||||
for rec in self:
|
for rec in self:
|
||||||
res = {}
|
res = {}
|
||||||
for field in parser:
|
for field in parser:
|
||||||
field_name, json_key, subparser = __parse_field(field)
|
field_name, json_key, subparser = self.__parse_field(field)
|
||||||
field_type = rec._fields[field_name].type
|
field_type = rec._fields[field_name].type
|
||||||
if subparser:
|
if subparser:
|
||||||
if field_type in ('one2many', 'many2many'):
|
if field_type in ('one2many', 'many2many'):
|
||||||
|
@ -71,6 +78,3 @@ def jsonify(self, parser):
|
||||||
res[json_key] = empty_value[field_type]
|
res[json_key] = empty_value[field_type]
|
||||||
result.append(res)
|
result.append(res)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
models.Model.jsonify = jsonify
|
|
||||||
|
|
|
@ -1,7 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# © 2016 Akretion (http://www.akretion.com)
|
|
||||||
# Sébastien BEAU <sebastien.beau@akretion.com>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
||||||
|
|
||||||
from . import test_get_parser
|
from . import test_get_parser
|
||||||
from . import test_ir_exports_line
|
from . import test_ir_exports_line
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
# © <YEAR(S)> <AUTHOR(S)>
|
# © <YEAR(S)> <AUTHOR(S)>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
class TestParser(TransactionCase):
|
class TestParser(TransactionCase):
|
||||||
|
@ -57,17 +57,18 @@ class TestParser(TransactionCase):
|
||||||
partner = self.env['res.partner'].create({
|
partner = self.env['res.partner'].create({
|
||||||
'name': 'Akretion',
|
'name': 'Akretion',
|
||||||
'country_id': self.env.ref('base.fr').id,
|
'country_id': self.env.ref('base.fr').id,
|
||||||
|
'lang': 'en_US', # default
|
||||||
'category_id': [(0, 0, {'name': 'Inovator'})],
|
'category_id': [(0, 0, {'name': 'Inovator'})],
|
||||||
'child_ids': [
|
'child_ids': [
|
||||||
(0, 0, {
|
(0, 0, {
|
||||||
'name': 'Sebatien Beau',
|
'name': 'Sebatien Beau',
|
||||||
'country_id': self.env.ref('base.fr').id
|
'country_id': self.env.ref('base.fr').id
|
||||||
})
|
})
|
||||||
]
|
],
|
||||||
})
|
})
|
||||||
expected_json = [{
|
expected_json = [{
|
||||||
u'lang': False,
|
u'lang': u'en_US',
|
||||||
u'comment': False,
|
u'comment': None,
|
||||||
u'credit_limit': 0.0,
|
u'credit_limit': 0.0,
|
||||||
u'name': u'Akretion',
|
u'name': u'Akretion',
|
||||||
u'color': 0,
|
u'color': 0,
|
||||||
|
@ -87,8 +88,9 @@ class TestParser(TransactionCase):
|
||||||
},
|
},
|
||||||
u'children': [],
|
u'children': [],
|
||||||
u'name': u'Sebatien Beau',
|
u'name': u'Sebatien Beau',
|
||||||
u'email': False
|
u'email': None
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
json_partner = partner.jsonify(parser)
|
json_partner = partner.jsonify(parser)
|
||||||
|
|
||||||
self.assertDictEqual(json_partner[0], expected_json[0])
|
self.assertDictEqual(json_partner[0], expected_json[0])
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
# © 2017 ACSONE SA/NV
|
# © 2017 ACSONE SA/NV
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
from openerp.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
from openerp.tests.common import TransactionCase
|
from odoo.tests.common import TransactionCase
|
||||||
|
|
||||||
|
|
||||||
class TestIrExportsLine(TransactionCase):
|
class TestIrExportsLine(TransactionCase):
|
||||||
|
|
Loading…
Reference in New Issue