Issue:
I'm encountering a TypeError: unsupported operand type(s) for +: 'SQL' and 'str'
when trying to install an Odoo module that was working fine in Odoo 17, but now has issues after migrating it to Odoo 18. The code that's causing the issue is:
def _select(self):
return super()._select() + ", sol.lot_id as location_lot_id"
def _group_by(self):
return super()._group_by() + " , sol.lot_id, "
Here is the complete code:
from odoo import fields, models
class RentalSchedule(models.Model):
_inherit = "sale.rental.schedule"
location_lot_id = fields.Many2one(
'stock.lot', 'Lot/serial number', readonly=True
)
def _select(self):
return super()._select() + ", sol.lot_id as location_lot_id"
def _group_by(self):
return super()._group_by() + " , sol.lot_id, "
I tried to wrap the string statement with the SQL utility from `odoo.utils.sql`. But the error still remained. Here is the complete code with the SQL utility:
from odoo import fields, models
from odoo.tools.sql import SQL
class RentalSchedule(models.Model):
_inherit = "sale.rental.schedule"
location_lot_id = fields.Many2one(
'stock.lot', 'Lot/serial number', readonly=True
)
def _select(self):
return super()._select() + SQL("sol.lot_id AS location_lot_id")
def _group_by(self):
return super()._group_by() + SQL("sol.lot_id")
It should be:
from odoo import fields, models
from odoo.tools.sql import SQL
class RentalSchedule(models.Model):
_inherit = "sale.rental.schedule"
location_lot_id = fields.Many2one(
'stock.lot', 'Lot/serial number', readonly=True
)
def _select(self):
return SQL("%s, sol.lot_id AS location_lot_id", super()._select())
def _group_by(self):
return SQL("%s, sol.lot_id", super()._group_by())