Set name clause on join condition instead of subquery
The name is a column from a table that is not available in the subquery. issue10257 review346001004
This commit is contained in:
@@ -508,11 +508,30 @@ class FieldTranslate(Field):
|
||||
|
||||
def _get_translation_join(self, Model, name,
|
||||
translation, model, table, from_, language):
|
||||
if backend.name == 'postgresql' and _sql_version >= (1, 1, 0):
|
||||
query = translation.select(
|
||||
translation.res_id.as_('res_id'),
|
||||
translation.value.as_('value'),
|
||||
translation.name.as_('name'),
|
||||
distinct=True,
|
||||
distinct_on=[translation.res_id, translation.name],
|
||||
order_by=[
|
||||
translation.res_id,
|
||||
translation.name,
|
||||
translation.id.desc])
|
||||
else:
|
||||
query = translation.select(
|
||||
translation.res_id.as_('res_id'),
|
||||
Min(translation.value).as_('value'),
|
||||
translation.name.as_('name'),
|
||||
group_by=[translation.res_id, translation.name])
|
||||
if Model.__name__ == 'ir.model':
|
||||
name_ = Concat(Concat(table.model, ','), name)
|
||||
type_ = 'model'
|
||||
res_id = -1
|
||||
elif Model.__name__ == 'ir.model.field':
|
||||
from_ = from_.join(model, 'LEFT',
|
||||
condition=model.id == table.model)
|
||||
name_ = Concat(Concat(model.model, ','), table.name)
|
||||
if name == 'field_description':
|
||||
type_ = 'field'
|
||||
@@ -523,26 +542,13 @@ class FieldTranslate(Field):
|
||||
name_ = '%s,%s' % (Model.__name__, name)
|
||||
type_ = 'model'
|
||||
res_id = table.id
|
||||
if backend.name == 'postgresql' and _sql_version >= (1, 1, 0):
|
||||
query = translation.select(
|
||||
translation.res_id.as_('res_id'),
|
||||
translation.value.as_('value'),
|
||||
distinct=True,
|
||||
distinct_on=[translation.res_id],
|
||||
order_by=[translation.res_id, translation.id.desc])
|
||||
else:
|
||||
query = translation.select(
|
||||
translation.res_id.as_('res_id'),
|
||||
Min(translation.value).as_('value'),
|
||||
group_by=[translation.res_id])
|
||||
query.where = (
|
||||
(translation.lang == language)
|
||||
& (translation.type == type_)
|
||||
& (translation.name == name_)
|
||||
& (translation.fuzzy == Literal(False))
|
||||
)
|
||||
return query, from_.join(query, 'LEFT',
|
||||
condition=(query.res_id == res_id))
|
||||
condition=(query.res_id == res_id) & (query.name == name_))
|
||||
|
||||
def _get_translation_column(self, Model, name):
|
||||
from trytond.ir.lang import get_parent_language
|
||||
|
||||
@@ -18,6 +18,58 @@ class IrTestCase(ModuleTestCase):
|
||||
'Test ir module'
|
||||
module = 'ir'
|
||||
|
||||
@with_transaction()
|
||||
def test_model_search_name(self):
|
||||
"Test searching on name of model"
|
||||
pool = Pool()
|
||||
Model = pool.get('ir.model')
|
||||
|
||||
record, = Model.search([
|
||||
('name', '=', "Language"),
|
||||
('module', '=', 'ir'),
|
||||
])
|
||||
self.assertEqual(record.name, "Language")
|
||||
|
||||
@with_transaction()
|
||||
def test_model_search_order(self):
|
||||
"Test searching and ordering on name of model"
|
||||
pool = Pool()
|
||||
Model = pool.get('ir.model')
|
||||
|
||||
records = Model.search([
|
||||
('name', 'in', ["Language", "Module"]),
|
||||
('module', '=', 'ir'),
|
||||
],
|
||||
order=[('name', 'ASC')])
|
||||
self.assertEqual([r.name for r in records], ["Language", "Module"])
|
||||
|
||||
@with_transaction()
|
||||
def test_model_field_search_description(self):
|
||||
"Test searching on description of model field"
|
||||
pool = Pool()
|
||||
ModelField = pool.get('ir.model.field')
|
||||
|
||||
field, = ModelField.search([
|
||||
('field_description', '=', "Name"),
|
||||
('model.model', '=', 'ir.lang'),
|
||||
('module', '=', 'ir'),
|
||||
])
|
||||
self.assertEqual(field.field_description, "Name")
|
||||
|
||||
@with_transaction()
|
||||
def test_model_field_search_order_description(self):
|
||||
"Test searching and ordering on description of model field"
|
||||
pool = Pool()
|
||||
ModelField = pool.get('ir.model.field')
|
||||
|
||||
fields = ModelField.search([
|
||||
('field_description', 'in', ["Name", "Code"]),
|
||||
('model.model', '=', 'ir.lang'),
|
||||
('module', '=', 'ir'),
|
||||
])
|
||||
self.assertEqual(
|
||||
[f.field_description for f in fields], ["Code", "Name"])
|
||||
|
||||
@with_transaction()
|
||||
def test_sequence_substitutions(self):
|
||||
'Test Sequence Substitutions'
|
||||
|
||||
Reference in New Issue
Block a user