Use column to order when translation value is empty

issue10094
review331871002
This commit is contained in:
Cédric Krier committed 2021-02-20 00:58:39 +01:00
1 parent fffb8efb5a
commit 3592175067
2 files changed
+26 -1

No files matched your search

+1 -1
View File
@@ -605,7 +605,7 @@ class FieldTranslate(Field):
column = Coalesce(NullIf(column, ''), translation.value)
language = get_parent_language(language)
return [Coalesce(column, self.sql_column(table))]
return [Coalesce(NullIf(column, ''), self.sql_column(table))]
def definition(self, model, language):
definition = super().definition(model, language)
+25
View File
@@ -776,6 +776,31 @@ class ModelSQLTranslationTestCase(TranslationTestCase):
self.assertEqual(record.name, "Foo")
self.assertEqual(other.name, "Baz")
@with_transaction()
def test_order_empty_translation(self):
"Test order on empty translation value"
pool = Pool()
Model = pool.get('test.modelsql.translation')
Translation = pool.get('ir.translation')
with Transaction().set_context(language=self.default_language):
records = Model.create(
[{'name': "A"}, {'name': "B"}, {'name': "C"}])
translation, = Translation.search([
('lang', '=', self.default_language),
('name', '=', 'test.modelsql.translation,name'),
('type', '=', 'model'),
('res_id', '=', records[1].id),
])
translation.value = ''
translation.save()
with Transaction().set_context(language=self.default_language):
self.assertEqual(
Model.search([], order=[('name', 'ASC')]),
records)
@with_transaction()
def test_search_unique_result(self):
"Test unique result on search"