Laurent Mignon (ACSONE)
8 years ago
committed by
Pierrick Brun
8 changed files with 204 additions and 59 deletions
-
23base_jsonify/README.rst
-
1base_jsonify/models/__init__.py
-
10base_jsonify/models/ir_export.py
-
35base_jsonify/models/ir_exports_line.py
-
32base_jsonify/models/models.py
-
1base_jsonify/tests/__init__.py
-
108base_jsonify/tests/test_get_parser.py
-
45base_jsonify/tests/test_ir_exports_line.py
@ -0,0 +1,35 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp.exceptions import ValidationError |
|||
from openerp import api, fields, models, _ |
|||
|
|||
|
|||
class IrExportsLine(models.Model): |
|||
_inherit = 'ir.exports.line' |
|||
_order = 'name' |
|||
|
|||
alias = fields.Char( |
|||
'Alias', |
|||
help=_('The complete path to the field where you can specify an ' |
|||
'alias on the a step as field:alias') |
|||
) |
|||
|
|||
@api.constrains('alias', 'name') |
|||
def _check_alias(self): |
|||
for rec in self: |
|||
if not rec.alias: |
|||
continue |
|||
names = rec.name.split('/') |
|||
names_with_alias = rec.alias.split('/') |
|||
if len(names) != len(names_with_alias): |
|||
raise ValidationError( |
|||
_("Name and Alias must have the same hierarchy depth")) |
|||
for name, name_with_alias in zip(names, names_with_alias): |
|||
field_name = name_with_alias.split(':')[0] |
|||
if name != field_name: |
|||
raise ValidationError( |
|||
_("The alias must reference the same field as in " |
|||
"name '%s' not in '%s'") % (name, name_with_alias) |
|||
) |
@ -0,0 +1,45 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2017 ACSONE SA/NV |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from openerp.exceptions import ValidationError |
|||
from openerp.tests.common import TransactionCase |
|||
|
|||
|
|||
class TestIrExportsLine(TransactionCase): |
|||
|
|||
def setUp(self): |
|||
super(TestIrExportsLine, self).setUp() |
|||
self.ir_export = self.env.ref('base_jsonify.ir_exp_partner') |
|||
|
|||
def test_alias_contrains(self): |
|||
ir_export_lines_model = self.env['ir.exports.line'] |
|||
with self.assertRaises(ValidationError): |
|||
# The field into the name must be also into the alias |
|||
ir_export_lines_model.create({ |
|||
'export_id': self.ir_export.id, |
|||
'name': 'name', |
|||
'alias': 'toto:my_alias' |
|||
}) |
|||
with self.assertRaises(ValidationError): |
|||
# The hierarchy into the alias must be the same as the one into |
|||
# the name |
|||
ir_export_lines_model.create({ |
|||
'export_id': self.ir_export.id, |
|||
'name': 'child_ids/child_ids/name', |
|||
'alias': 'child_ids:children/name' |
|||
}) |
|||
with self.assertRaises(ValidationError): |
|||
# The hierarchy into the alias must be the same as the one into |
|||
# the name and must contains the same fields as into the name |
|||
ir_export_lines_model.create({ |
|||
'export_id': self.ir_export.id, |
|||
'name': 'child_ids/child_ids/name', |
|||
'alias': 'child_ids:children/category_id:category/name' |
|||
}) |
|||
line = ir_export_lines_model.create({ |
|||
'export_id': self.ir_export.id, |
|||
'name': 'child_ids/child_ids/name', |
|||
'alias': 'child_ids:children/child_ids:children/name' |
|||
}) |
|||
self.assertTrue(line) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue