| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
from odoorpc.models import Model |
| 4 |
from odoorpc.tests import LoginTestCase |
| 5 |
from odoorpc.tools import v |
| 6 |
|
| 7 |
|
| 8 |
class TestFieldReference(LoginTestCase): |
| 9 |
def test_field_reference_read(self): |
| 10 |
# 8.0 and 9.0 |
| 11 |
if v(self.odoo.version) < v('10'): |
| 12 |
Claim = self.odoo.env['crm.claim'] |
| 13 |
claim_id = Claim.search([])[0] |
| 14 |
# Test field containing a value |
| 15 |
self.odoo.execute( |
| 16 |
'crm.claim', 'write', [claim_id], {'ref': 'res.partner,1'} |
| 17 |
) |
| 18 |
claim = Claim.browse(claim_id) |
| 19 |
self.assertIsInstance(claim.ref, Model) |
| 20 |
self.assertEqual(claim.ref._name, 'res.partner') |
| 21 |
self.assertEqual(claim.ref.id, 1) |
| 22 |
# Test if empty field returns False (unable to guess the model to use) |
| 23 |
self.odoo.execute('crm.claim', 'write', [claim_id], {'ref': None}) |
| 24 |
claim = Claim.browse(claim_id) |
| 25 |
self.assertEqual(claim.ref, False) |
| 26 |
# 10.0 |
| 27 |
elif v(self.odoo.version) < v('11'): |
| 28 |
Subscription = self.odoo.env['subscription.subscription'] |
| 29 |
fields_list = list(Subscription.fields_get([])) |
| 30 |
vals = Subscription.default_get(fields_list) |
| 31 |
vals['name'] = "ODOORPC TEST (fields.Reference)" |
| 32 |
vals['doc_source'] = 'res.partner,1' |
| 33 |
subscription_id = Subscription.create(vals) |
| 34 |
# Test field containing a value |
| 35 |
subscription = Subscription.browse(subscription_id) |
| 36 |
self.assertIsInstance(subscription.doc_source, Model) |
| 37 |
self.assertEqual(subscription.doc_source._name, 'res.partner') |
| 38 |
self.assertEqual(subscription.doc_source.id, 1) |
| 39 |
# 11.0 |
| 40 |
else: |
| 41 |
Menu = self.odoo.env['ir.ui.menu'] |
| 42 |
fields_list = list(Menu.fields_get([])) |
| 43 |
vals = Menu.default_get(fields_list) |
| 44 |
vals['name'] = "ODOORPC TEST (fields.Reference)" |
| 45 |
action = self.odoo.env.ref('base.action_partner_form') |
| 46 |
vals['action'] = '{},{}'.format(action._name, action.id) |
| 47 |
menu_id = Menu.create(vals) |
| 48 |
# Test field containing a value |
| 49 |
menu = Menu.browse(menu_id) |
| 50 |
self.assertIsInstance(menu.action, Model) |
| 51 |
self.assertEqual(menu.action._name, action._name) |
| 52 |
self.assertEqual(menu.action.id, action.id) |
| 53 |
|
| 54 |
def test_field_reference_write(self): |
| 55 |
# TODO |
| 56 |
pass |