changeset b4662dcd0a71 in trytond:default
details: https://hg.tryton.org/trytond?cmd=changeset;node=b4662dcd0a71
description:
        Allow to use dotted notation in Model.get_id

        issue8890
        review282481004
diffstat:

 trytond/ir/model.py      |   4 +++-
 trytond/tests/test_ir.py |  24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletions(-)

diffs (51 lines):

diff -r d03e797cd908 -r b4662dcd0a71 trytond/ir/model.py
--- a/trytond/ir/model.py       Mon Jan 13 23:58:14 2020 +0100
+++ b/trytond/ir/model.py       Mon Jan 20 22:18:27 2020 +0100
@@ -1198,10 +1198,12 @@
         return model in models
 
     @classmethod
-    def get_id(cls, module, fs_id):
+    def get_id(cls, module, fs_id=None):
         """
         Return for an fs_id the corresponding db_id.
         """
+        if fs_id is None:
+            module, fs_id = module.split('.', 1)
         key = (module, fs_id)
         id_ = cls._get_id_cache.get(key)
         if id_ is not None:
diff -r d03e797cd908 -r b4662dcd0a71 trytond/tests/test_ir.py
--- a/trytond/tests/test_ir.py  Mon Jan 13 23:58:14 2020 +0100
+++ b/trytond/tests/test_ir.py  Mon Jan 20 22:18:27 2020 +0100
@@ -64,6 +64,30 @@
         for date, format_, result in test_data:
             self.assertEqual(lang.strftime(date, format_), result)
 
+    @with_transaction()
+    def test_model_data_get_id(self):
+        "Test ModelData.get_id"
+        pool = Pool()
+        ModelData = pool.get('ir.model.data')
+        User = pool.get('res.user')
+
+        admin_id = ModelData.get_id('res', 'user_admin')
+        admin, = User.search([('login', '=', 'admin')])
+
+        self.assertEqual(admin_id, admin.id)
+
+    @with_transaction()
+    def test_model_data_get_id_dot(self):
+        "Test ModelData.get_id with dot"
+        pool = Pool()
+        ModelData = pool.get('ir.model.data')
+        User = pool.get('res.user')
+
+        admin_id = ModelData.get_id('res.user_admin')
+        admin, = User.search([('login', '=', 'admin')])
+
+        self.assertEqual(admin_id, admin.id)
+
 
 def suite():
     return unittest.TestLoader().loadTestsFromTestCase(IrTestCase)

Reply via email to