콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
391 화면

hi all 

in a learning context, I wanted to test the filtering and sorting functions, but I had some problems, the code below

car_car.py Model (My car mode)

from odoo import models,fields


class Car(models.Model):
_name="car.car"
_description = "Car models"

name=fields.Char(string="Car")
carpooling_ids = fields.One2many("carpooling.carpooling",'car_id',string="Carpoolings")
brand=fields.Char(string="Brand")


the functions are located in carpooling.carpooling model.

@api.onchange('car_id')
def on_change_car_id(self):
cars = self.env['car.car'].search([]).sorted(key=lambda car: car.name)
print(cars)

the function above when fired raise error below

error TypeError: '<' not supported between instances of 'str' and 'bool'

the name field is of type Char (string)

in the same way 

@api.onchange('car_id')
def on_change_car_id(self):
cars = self.env['car.car'].search([]).filtered(lambda car: "skoda" in car.name)
print(cars)

i am getting following error 

TypeError: argument of type 'bool' is not iterable

I am using Odoo 17 and python 3.12, whats the wrong with my code, everything seems ok ?

아바타
취소
작성자 베스트 답변

I found the problem myself, in fact I had null name fields in my database, 

it's still quite strange, the best is to ignore the null fields instead of raising erros

아바타
취소