Browse Source

Merge PR #1661 into 10.0

Signed-off-by lmignon
10.0
OCA-git-bot 5 years ago
parent
commit
9be5571a4f
  1. 20
      base_custom_info/models/custom_info_template.py
  2. 1
      base_jsonify/models/ir_exports_line.py
  3. 26
      base_jsonify/tests/test_get_parser.py

20
base_custom_info/models/custom_info_template.py

@ -53,15 +53,15 @@ class CustomInfoTemplate(models.Model):
self._inverse_model() self._inverse_model()
@api.multi @api.multi
@api.constrains("model_id")
def _check_model(self):
"""Avoid error when updating base module and a submodule extends a
model that falls out of this one's dependency graph.
def _check_model_update_allowed(self, model_id):
"""Check if the template's model can be updated.
Template can be updated only if no property values already exists for
this template
""" """
for record in self: for record in self:
with self.env.norecompute():
oldmodels = record.mapped("property_ids.info_value_ids.model")
if oldmodels and record.model not in oldmodels:
if (model_id != record.model_id.id
and record.mapped("property_ids.info_value_ids")):
raise ValidationError( raise ValidationError(
_("You cannot change the model because it is in use.") _("You cannot change the model because it is in use.")
) )
@ -74,3 +74,9 @@ class CustomInfoTemplate(models.Model):
model.check_access_rights(operation) model.check_access_rights(operation)
model.check_access_rule(operation) model.check_access_rule(operation)
return super(CustomInfoTemplate, self).check_access_rule(operation) return super(CustomInfoTemplate, self).check_access_rule(operation)
@api.multi
def write(self, vals):
if 'model_id' in vals:
self._check_model_update_allowed(vals['model_id'])
return super(CustomInfoTemplate, self).write(vals)

1
base_jsonify/models/ir_exports_line.py

@ -8,7 +8,6 @@ from odoo import api, fields, models, _
class IrExportsLine(models.Model): class IrExportsLine(models.Model):
_inherit = 'ir.exports.line' _inherit = 'ir.exports.line'
_order = 'name'
alias = fields.Char( alias = fields.Char(
'Alias', 'Alias',

26
base_jsonify/tests/test_get_parser.py

@ -9,30 +9,32 @@ class TestParser(TransactionCase):
def test_getting_parser(self): def test_getting_parser(self):
expected_parser = [ expected_parser = [
u'name',
u'active', u'active',
u'credit_limit',
u'color',
(u'category_id', [u'name']), (u'category_id', [u'name']),
(u'child_ids', [(
u'child_ids', [u'name']),
(u'country_id', [u'code', u'name']),
u'email', u'id',
u'name'
(u'country_id', [u'name', u'code']),
(u'child_ids', [
u'name',
u'id',
u'email',
(u'country_id', [u'name', u'code']),
(u'child_ids', [u'name']),
]), ]),
u'color',
u'comment',
(u'country_id', [u'code', u'name']),
u'credit_limit',
u'lang', u'lang',
u'name']
u'comment'
]
exporter = self.env.ref('base_jsonify.ir_exp_partner') exporter = self.env.ref('base_jsonify.ir_exp_partner')
parser = exporter.get_json_parser() parser = exporter.get_json_parser()
self.assertEqual(parser, expected_parser)
self.assertListEqual(parser, expected_parser)
# modify an ir.exports_line to put an alias for a field # modify an ir.exports_line to put an alias for a field
self.env.ref('base_jsonify.category_id_name').write({ self.env.ref('base_jsonify.category_id_name').write({
'alias': 'category_id:category/name' 'alias': 'category_id:category/name'
}) })
expected_parser[1] = (u'category_id:category', [u'name'])
expected_parser[4] = (u'category_id:category', [u'name'])
parser = exporter.get_json_parser() parser = exporter.get_json_parser()
self.assertEqual(parser, expected_parser) self.assertEqual(parser, expected_parser)

Loading…
Cancel
Save