'test related fields.'

def test_25_related(self):

    message = self.env.ref('test_new_api.message_0_0')
    discussion = message.discussion
    field = message._fields['discussion_name']
    self.assertFalse(field.store)
    self.assertFalse(field.readonly)
    self.assertEqual(message.discussion_name, discussion.name)
    discussion.name = 'Foo'
    self.assertEqual(message.discussion_name, 'Foo')
    message.discussion_name = 'Bar'
    self.assertEqual(discussion.name, 'Bar')
    self.assertEqual(message.discussion_name, 'Bar')
    discussion1 = discussion.create({'name': 'X1'})
    discussion2 = discussion.create({'name': 'X2'})
    discussion1.participants = discussion2.participants = self.env.user
    message1 = message.create({'discussion': discussion1.id})
    message2 = message.create({'discussion': discussion2.id})
    self.assertEqual(message1.discussion_name, 'X1')
    self.assertEqual(message2.discussion_name, 'X2')
    (message1 + message2).write({'discussion_name': 'X3'})
    self.assertEqual(discussion1.name, 'X3')
    self.assertEqual(discussion2.name, 'X3')
    search_on_related = self.env['test_new_api.message'].search([('discussion_name', '=', 'Bar')])
    search_on_regular = self.env['test_new_api.message'].search([('discussion.name', '=', 'Bar')])
    self.assertEqual(search_on_related, search_on_regular)
    message_field = message.fields_get(['discussion_name'])['discussion_name']
    discussion_field = discussion.fields_get(['name'])['name']
    self.assertEqual(message_field['help'], discussion_field['help'])
