3

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")

1 Answer 1

1

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())
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, it worked very well now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.