Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
349 Widoki

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 ?

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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

Awatar
Odrzuć