diff --git a/addons/account/models/account_bank_statement.py b/addons/account/models/account_bank_statement.py index a6a37853b38..e180269917b 100644 --- a/addons/account/models/account_bank_statement.py +++ b/addons/account/models/account_bank_statement.py @@ -175,9 +175,10 @@ class AccountBankStatement(models.Model): journal_type = self.env.context.get('journal_type', False) company_id = self.env.company.id if journal_type: - journals = self.env['account.journal'].search([('type', '=', journal_type), ('company_id', '=', company_id)]) - if journals: - return journals[0] + return self.env['account.journal'].search([ + ('type', '=', journal_type), + ('company_id', '=', company_id) + ], limit=1) return self.env['account.journal'] @api.depends('balance_start', 'previous_statement_id') diff --git a/addons/im_livechat/controllers/main.py b/addons/im_livechat/controllers/main.py index a37a53d6b5e..3078ebefae2 100644 --- a/addons/im_livechat/controllers/main.py +++ b/addons/im_livechat/controllers/main.py @@ -56,11 +56,9 @@ class LivechatController(http.Controller): if available: # find the country from the request country_id = False - country_code = request.session.geoip and request.session.geoip.get('country_code') or False + country_code = request.session.geoip.get('country_code') if request.session.geoip else False if country_code: - country_ids = request.env['res.country'].sudo().search([('code', '=', country_code)]) - if country_ids: - country_id = country_ids[0].id + country_id = request.env['res.country'].sudo().search([('code', '=', country_code)], limit=1).id # extract url url = request.httprequest.headers.get('Referer') # find the first matching rule for the given country and url @@ -111,14 +109,13 @@ class LivechatController(http.Controller): 'is_internal': False, } if not channel.rating_ids: - res_model_id = request.env['ir.model'].sudo().search([('model', '=', channel._name)], limit=1).id values.update({ 'res_id': channel.id, - 'res_model_id': res_model_id, + 'res_model_id': request.env['ir.model']._get_id('mail.channel'), }) # find the partner (operator) if channel.channel_partner_ids: - values['rated_partner_id'] = channel.channel_partner_ids[0] and channel.channel_partner_ids[0].id or False + values['rated_partner_id'] = channel.channel_partner_ids[0].id # if logged in user, set its partner on rating values['partner_id'] = request.env.user.partner_id.id if request.session.uid else False # create the rating diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py index 87b1b914806..788afa1319c 100644 --- a/addons/mass_mailing/wizard/mail_compose_message.py +++ b/addons/mass_mailing/wizard/mail_compose_message.py @@ -22,7 +22,7 @@ class MailComposeMessage(models.TransientModel): # use only for allowed models in mass mailing if self.composition_mode == 'mass_mail' and \ (self.mass_mailing_name or self.mass_mailing_id) and \ - self.env['ir.model'].sudo().search([('model', '=', self.model), ('is_mail_thread', '=', True)], limit=1): + self.env['ir.model'].sudo().search_count([('model', '=', self.model), ('is_mail_thread', '=', True)]): mass_mailing = self.mass_mailing_id if not mass_mailing: mass_mailing = self.env['mailing.mailing'].create({ diff --git a/addons/rating/models/mail_thread.py b/addons/rating/models/mail_thread.py index e2182ea9cb5..8725bc81c44 100644 --- a/addons/rating/models/mail_thread.py +++ b/addons/rating/models/mail_thread.py @@ -16,11 +16,10 @@ class MailThread(models.AbstractModel): # create rating.rating record linked to given rating_value. Using sudo as portal users may have # rights to create messages and therefore ratings (security should be checked beforehand) if rating_value: - ir_model = self.env['ir.model'].sudo().search([('model', '=', self._name)]) self.env['rating.rating'].sudo().create({ 'rating': float(rating_value) if rating_value is not None else False, 'feedback': rating_feedback, - 'res_model_id': ir_model.id, + 'res_model_id': self.env['ir.model']._get_id(self._name), 'res_id': self.id, 'message_id': message.id, 'consumed': True, diff --git a/addons/rating/models/rating_mixin.py b/addons/rating/models/rating_mixin.py index 55c8e35f566..a2c799547a8 100644 --- a/addons/rating/models/rating_mixin.py +++ b/addons/rating/models/rating_mixin.py @@ -131,11 +131,10 @@ class RatingMixin(models.AbstractModel): rated_partner = self.rating_get_rated_partner_id() ratings = self.rating_ids.sudo().filtered(lambda x: x.partner_id.id == partner.id and not x.consumed) if not ratings: - record_model_id = self.env['ir.model'].sudo().search([('model', '=', self._name)], limit=1).id rating = self.env['rating.rating'].sudo().create({ 'partner_id': partner.id, 'rated_partner_id': rated_partner.id, - 'res_model_id': record_model_id, + 'res_model_id': self.env['ir.model']._get_id(self._name), 'res_id': self.id, 'is_internal': False, })