계산 된 필드에서 store=True
을 사용하지 않는 것이 좋지 않을 수도 있으므로 사용하지 않는 것이 좋습니다. 그래서, 난 당신이 같은 것을 할 수 있다고 생각 :
class Version(models.Model):
_name = 'product_cars_application.version'
name = fields.Char(
compute="_compute_name",
search="_search_name",
)
@api.one
def _compute_name(self):
self.name = "%s %s %s (%s)" % (self.brand_id,
self.model_id.name,
self.vname,
self.year_id)
def _search_name(self, operator, value):
""" Actually this converts a domain into another one.
With this new domain Odoo can search well
A list of ids is the most easy way without computed fields
* [('id', 'in', id_list)]
"""
if operator == 'ilike':
name = self.env.context.get('name', False)
if name is not False:
id_list = []
product_cars = self.env['product_cars_application.version'].search([])
for car in product_cars:
if name in car.name:
id_list.append(lot.id)
return [('id', 'in', lot_id_list)]
else:
return [('id', 'in', [])]
else:
_logger.error(
'The field name is not searchable'
' with the operator: {}',format(operator)
)
당신은 항상 모든 레코드를 통해 루프가 있기 때문에 그것은 비효율적이다,하지만 난 그것을 할 수있는 유일한 안전 모드라고 생각합니다.
하지만 특수한 경우에 수행 할 수있는 가장 좋은 방법은 계산되지 않은 일반 문자로 필드 이름을 만드는 것입니다. 이름을 만들려면 기본값을 설정할 수 있습니다. 이 값은 저장되고 문제는 사라질 것입니다.
이 일부 변경 해야 할 데프 _name_search (자기, 이름, 인수 = 없음, 연산자 = 'ILIKE', 한계 = 100) : 경우 연산자 == '와 같은' 연산자 = 'ILIKE' 버전 = self.search ([('name', operator, name)], 제한 = 한계) 반환 버전. 이름 _get() –
확인. 내 필요에 따라 코드를 변경했습니다. 같은 문제가있는 누군가는 우리가 여기서 한 일을 더 잘 이해할 수 있습니다. – Nope
'store = True'는 계산 된 필드에서 사용하지 않는 것이 좋을 수도 있기 때문에 사용하지 않는 것이 좋습니다. – ChesuCR