[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:
@@ -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
|
||||
|
||||
@@ -173,6 +173,7 @@
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="parent"/>
|
||||
<field name="dummy"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user