[FIX] fields: handle the case of fields declared with store=False

Those fields should be considered as "dummy" fields": they are typically useful
for hackish onchange methods that need to store something into a form.
This commit is contained in:
Raphael Collet
2015-07-06 11:02:39 +02:00
parent 995cb87c62
commit 5ebc100253
4 changed files with 10 additions and 1 deletions
+1
View File
@@ -31,6 +31,7 @@ class Category(models.Model):
name = fields.Char(required=True)
parent = fields.Many2one('test_new_api.category')
display_name = fields.Char(compute='_compute_display_name', inverse='_inverse_display_name')
dummy = fields.Char(store=False)
@api.one
@api.depends('name', 'parent.display_name') # this definition is recursive
@@ -61,6 +61,13 @@ class TestNewFields(common.TransactionCase):
def test_10_non_stored(self):
""" test non-stored fields """
# a field declared with store=False should not have a column
field = self.env['test_new_api.category']._fields['dummy']
self.assertFalse(field.store)
self.assertFalse(field.compute)
self.assertFalse(field.inverse)
self.assertFalse(field.column)
# find messages
for message in self.env['test_new_api.message'].search([]):
# check definition of field
+1
View File
@@ -173,6 +173,7 @@
<group>
<field name="name"/>
<field name="parent"/>
<field name="dummy"/>
</group>
</sheet>
</form>
+1 -1
View File
@@ -671,7 +671,7 @@ class Field(object):
def to_column(self):
""" Return a column object corresponding to `self`, or ``None``. """
if not self.store and self.compute:
if not self.store and (self.compute or not self.column):
# non-stored computed fields do not have a corresponding column
self.column = None
return None