summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorMartin Trigaux <mat@openerp.com>2014-07-16 10:35:52 +0200
committerOlivier Dony <odo@openerp.com>2014-07-25 13:58:59 +0200
commitf138aa26085d103a88dbd8bb73fb8bf5517298ad (patch)
tree3b2c3db5a4da6ee1497cf312b2ddff4655c9aecd /addons
parentbcd9456db594496cbf0f539f96c7bb09717b549c (diff)
[FIX] models: display_name and name_get mismatch
- display_name uses name_get and not the other way around: name_get should not call _compute_display_name, _compute_display_name should call name_get. The previous behaviour was not backward-compatible with the old api. All the models redefining name_get would have 2 different behaviors between name_get and display_name. - Do not set an inverse function to display_name: In most cases, writing on display_name writes on _rec_name (if any, not mandatory). If the display_name computation is redefined, we need to redefine as well the inverse method to avoid unexpected behaviour This required to also modify tests in base_import as readonly fields are avoided. - Remove search method on display_name: For the same reason as for the first point, it could be good that searching on display_name use name_search (and not the other way around). However doing this would be very inefficiant (need to do the search, without limit, extract the ids of the name_get result just to generate a subdomain ('id', 'in', [...]). As in most cases it would anyway mean to search on the _rec_name it's better to directly do so. - Changing label to avoid mismatch: In view displaying the list of fields or when a match is made on the label of a field (e.g. when importing csv file, matching is made on both label and technical name), the fact that display_name field has ' Calling it 'Display Name' will avoid most errors. - remove display_name definition from website_forum_doc,ir_model: These fields are doing the same thing as the display_name of the new api, we can remove them. We need to keep the one for res.partner as it's a stored field.
Diffstat (limited to 'addons')
-rw-r--r--addons/account/account_invoice.py9
-rw-r--r--addons/base_import/tests/test_cases.py16
-rw-r--r--addons/event/event.py13
-rw-r--r--addons/website_forum_doc/models/documentation.py2
4 files changed, 18 insertions, 22 deletions
diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py
index 9314b1c3715..6221fb5928d 100644
--- a/addons/account/account_invoice.py
+++ b/addons/account/account_invoice.py
@@ -1005,15 +1005,18 @@ class account_invoice(models.Model):
#TODO: implement messages system
return True
- @api.one
- def _compute_display_name(self):
+ @api.multi
+ def name_get(self):
TYPES = {
'out_invoice': _('Invoice'),
'in_invoice': _('Supplier Invoice'),
'out_refund': _('Refund'),
'in_refund': _('Supplier Refund'),
}
- self.display_name = "%s %s" % (self.number or TYPES[self.type], self.name or '')
+ result = []
+ for inv in self:
+ result.append((inv.id, "%s %s" % (inv.number or TYPES[inv.type], inv.name or '')))
+ return result
@api.model
def name_search(self, name, args=None, operator='ilike', limit=100):
diff --git a/addons/base_import/tests/test_cases.py b/addons/base_import/tests/test_cases.py
index ac5a4440523..bad79bc7cdc 100644
--- a/addons/base_import/tests/test_cases.py
+++ b/addons/base_import/tests/test_cases.py
@@ -11,18 +11,10 @@ ID_FIELD = {
'required': False,
'fields': [],
}
-DISPLAY_NAME_FIELD = {
- 'id': 'display_name',
- 'name': 'display_name',
- 'string': "Name",
- 'required': False,
- 'fields': [],
-}
def make_field(name='value', string='unknown', required=False, fields=[]):
return [
ID_FIELD,
- DISPLAY_NAME_FIELD,
{'id': name, 'name': name, 'string': string, 'required': required, 'fields': fields},
]
@@ -50,7 +42,7 @@ class test_basic_fields(BaseImportCase):
def test_readonly(self):
""" Readonly fields should be filtered out"""
- self.assertEqualFields(self.get_fields('char.readonly'), [ID_FIELD, DISPLAY_NAME_FIELD])
+ self.assertEqualFields(self.get_fields('char.readonly'), [ID_FIELD])
def test_readonly_states(self):
""" Readonly fields with states should not be filtered out"""
@@ -59,12 +51,12 @@ class test_basic_fields(BaseImportCase):
def test_readonly_states_noreadonly(self):
""" Readonly fields with states having nothing to do with
readonly should still be filtered out"""
- self.assertEqualFields(self.get_fields('char.noreadonly'), [ID_FIELD, DISPLAY_NAME_FIELD])
+ self.assertEqualFields(self.get_fields('char.noreadonly'), [ID_FIELD])
def test_readonly_states_stillreadonly(self):
""" Readonly fields with readonly states leaving them readonly
always... filtered out"""
- self.assertEqualFields(self.get_fields('char.stillreadonly'), [ID_FIELD, DISPLAY_NAME_FIELD])
+ self.assertEqualFields(self.get_fields('char.stillreadonly'), [ID_FIELD])
def test_m2o(self):
""" M2O fields should allow import of themselves (name_get),
@@ -92,7 +84,6 @@ class test_o2m(BaseImportCase):
def test_shallow(self):
self.assertEqualFields(self.get_fields('o2m'), make_field(fields=[
ID_FIELD,
- DISPLAY_NAME_FIELD,
# FIXME: should reverse field be ignored?
{'id': 'parent_id', 'name': 'parent_id', 'string': 'unknown', 'required': False, 'fields': [
{'id': 'parent_id', 'name': 'id', 'string': 'External ID', 'required': False, 'fields': []},
@@ -250,7 +241,6 @@ class test_preview(TransactionCase):
# Order depends on iteration order of fields_get
self.assertItemsEqual(result['fields'], [
ID_FIELD,
- DISPLAY_NAME_FIELD,
{'id': 'name', 'name': 'name', 'string': 'Name', 'required':False, 'fields': []},
{'id': 'somevalue', 'name': 'somevalue', 'string': 'Some Value', 'required':True, 'fields': []},
{'id': 'othervalue', 'name': 'othervalue', 'string': 'Other Variable', 'required':False, 'fields': []},
diff --git a/addons/event/event.py b/addons/event/event.py
index e5a12fb02d2..325682f86b3 100644
--- a/addons/event/event.py
+++ b/addons/event/event.py
@@ -185,12 +185,15 @@ class event_event(models.Model):
for reg in self.registration_ids
)
- @api.one
+ @api.multi
@api.depends('name', 'date_begin', 'date_end')
- def _compute_display_name(self):
- dates = [dt.split(' ')[0] for dt in [self.date_begin, self.date_end] if dt]
- dates = sorted(set(dates))
- self.display_name = '%s (%s)' % (self.name, ' - '.join(dates))
+ def name_get(self):
+ result = []
+ for event in self:
+ dates = [dt.split(' ')[0] for dt in [event.date_begin, event.date_end] if dt]
+ dates = sorted(set(dates))
+ result.append((event.id, '%s (%s)' % (event.name, ' - '.join(dates))))
+ return result
@api.one
@api.constrains('seats_max', 'seats_available')
diff --git a/addons/website_forum_doc/models/documentation.py b/addons/website_forum_doc/models/documentation.py
index c393f6eec56..655040fb16f 100644
--- a/addons/website_forum_doc/models/documentation.py
+++ b/addons/website_forum_doc/models/documentation.py
@@ -24,13 +24,13 @@ class Documentation(osv.Model):
res.append((record['id'], name))
return res
+ # TODO master remove me
def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None):
res = self.name_get(cr, uid, ids, context=context)
return dict(res)
_columns = {
'sequence': fields.integer('Sequence'),
- 'display_name': fields.function(_name_get_fnc, type="char", string='Full Name'),
'name': fields.char('Name', required=True, translate=True),
'introduction': fields.html('Introduction', translate=True),
'parent_id': fields.many2one('forum.documentation.toc', 'Parent Table Of Content', ondelete='cascade'),