diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index 7441fe38ef..7f8dcb7948 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -484,7 +484,7 @@ class account_journal(models.Model): action = self.env["ir.actions.act_window"]._for_xml_id(action_name) context = self._context.copy() - if 'context' in action and type(action['context']) == str: + if 'context' in action and isinstance(action['context'], str): context.update(ast.literal_eval(action['context'])) else: context.update(action.get('context', {})) diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 7c6565c947..36420a4bc1 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -278,7 +278,7 @@ class ResPartner(models.Model): def _asset_difference_search(self, account_type, operator, operand): if operator not in ('<', '=', '>', '>=', '<='): return [] - if type(operand) not in (float, int): + if not isinstance(operand, (float, int)): return [] sign = 1 if account_type == 'payable': diff --git a/addons/account/models/sequence_mixin.py b/addons/account/models/sequence_mixin.py index 1a9435338a..48b632a9e4 100644 --- a/addons/account/models/sequence_mixin.py +++ b/addons/account/models/sequence_mixin.py @@ -46,7 +46,7 @@ class SequenceMixin(models.AbstractModel): )) def __init__(self, pool, cr): - api.constrains(self._sequence_field, self._sequence_date_field)(type(self)._constrains_date_sequence) + api.constrains(self._sequence_field, self._sequence_date_field)(pool[self._name]._constrains_date_sequence) return super().__init__(pool, cr) def _constrains_date_sequence(self): diff --git a/addons/auth_totp/models/res_users.py b/addons/auth_totp/models/res_users.py index 775496c08f..7328384935 100644 --- a/addons/auth_totp/models/res_users.py +++ b/addons/auth_totp/models/res_users.py @@ -35,7 +35,7 @@ class Users(models.Model): init_res = super().__init__(pool, cr) if not sql.column_exists(cr, self._table, "totp_secret"): cr.execute("ALTER TABLE res_users ADD COLUMN totp_secret varchar") - type(self).SELF_READABLE_FIELDS = self.SELF_READABLE_FIELDS + ['totp_enabled', 'totp_trusted_device_ids'] + pool[self._name].SELF_READABLE_FIELDS = self.SELF_READABLE_FIELDS + ['totp_enabled', 'totp_trusted_device_ids'] return init_res def _mfa_type(self): diff --git a/addons/base_automation/models/base_automation.py b/addons/base_automation/models/base_automation.py index fba80fdfed..8863f1b17d 100644 --- a/addons/base_automation/models/base_automation.py +++ b/addons/base_automation/models/base_automation.py @@ -432,7 +432,7 @@ class BaseAutomation(models.Model): """ Patch method `name` on `model`, unless it has been patched already. """ if model not in patched_models[name]: patched_models[name].add(model) - ModelClass = type(model) + ModelClass = model.env.registry[model._name] origin = getattr(ModelClass, name) method.origin = origin wrapped = api.propagate(origin, method) diff --git a/addons/google_gmail/controllers/main.py b/addons/google_gmail/controllers/main.py index d6a3f9256f..38fe7dfe19 100644 --- a/addons/google_gmail/controllers/main.py +++ b/addons/google_gmail/controllers/main.py @@ -43,7 +43,7 @@ class GoogleGmailController(http.Controller): model = request.env[model_name] - if not issubclass(type(model), request.env.registry['google.gmail.mixin']): + if not isinstance(model, request.env.registry['google.gmail.mixin']): # The model must inherits from the "google.gmail.mixin" mixin raise Forbidden() diff --git a/addons/hr/models/res_users.py b/addons/hr/models/res_users.py index 359b7230c3..8fa59bea58 100644 --- a/addons/hr/models/res_users.py +++ b/addons/hr/models/res_users.py @@ -136,8 +136,8 @@ class User(models.Model): init_res = super(User, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + hr_readable_fields + hr_writable_fields - type(self).SELF_WRITEABLE_FIELDS = type(self).SELF_WRITEABLE_FIELDS + hr_writable_fields + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + hr_readable_fields + hr_writable_fields + pool[self._name].SELF_WRITEABLE_FIELDS = pool[self._name].SELF_WRITEABLE_FIELDS + hr_writable_fields return init_res @api.model diff --git a/addons/hr_attendance/models/res_users.py b/addons/hr_attendance/models/res_users.py index be22e6f3f6..e465e7d7fc 100644 --- a/addons/hr_attendance/models/res_users.py +++ b/addons/hr_attendance/models/res_users.py @@ -27,4 +27,4 @@ class User(models.Model): ] super(User, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + attendance_readable_fields + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + attendance_readable_fields diff --git a/addons/hr_contract/models/hr_contract.py b/addons/hr_contract/models/hr_contract.py index 33e757d8b5..87fc80648a 100644 --- a/addons/hr_contract/models/hr_contract.py +++ b/addons/hr_contract/models/hr_contract.py @@ -77,7 +77,7 @@ class Contract(models.Model): contract.calendar_mismatch = contract.resource_calendar_id != contract.employee_id.resource_calendar_id def _expand_states(self, states, domain, order): - return [key for key, val in type(self).state.selection] + return [key for key, val in self._fields['state'].selection] @api.depends('employee_id') def _compute_employee_contract(self): diff --git a/addons/hr_contract/models/res_users.py b/addons/hr_contract/models/res_users.py index 18493c9860..8c5e342074 100644 --- a/addons/hr_contract/models/res_users.py +++ b/addons/hr_contract/models/res_users.py @@ -21,5 +21,5 @@ class User(models.Model): ] init_res = super(User, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + contract_readable_fields + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + contract_readable_fields return init_res diff --git a/addons/hr_expense/models/hr_employee.py b/addons/hr_expense/models/hr_employee.py index ac08a86448..6475272178 100644 --- a/addons/hr_expense/models/hr_employee.py +++ b/addons/hr_expense/models/hr_employee.py @@ -53,5 +53,5 @@ class User(models.Model): """ init_res = super(User, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['expense_manager_id'] + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + ['expense_manager_id'] return init_res diff --git a/addons/hr_fleet/models/res_users.py b/addons/hr_fleet/models/res_users.py index edf9d1722c..562df52894 100644 --- a/addons/hr_fleet/models/res_users.py +++ b/addons/hr_fleet/models/res_users.py @@ -16,7 +16,7 @@ class User(models.Model): """ init_res = super(User, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['employee_cars_count'] + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + ['employee_cars_count'] return init_res def action_get_claim_report(self): diff --git a/addons/hr_holidays/models/res_users.py b/addons/hr_holidays/models/res_users.py index d1e22bec73..66dfc1c3ad 100644 --- a/addons/hr_holidays/models/res_users.py +++ b/addons/hr_holidays/models/res_users.py @@ -38,7 +38,7 @@ class User(models.Model): ] init_res = super(User, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + readable_fields + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + readable_fields return init_res def _compute_im_status(self): diff --git a/addons/hr_maintenance/models/res_users.py b/addons/hr_maintenance/models/res_users.py index 0b4baf53f9..adb08a701c 100644 --- a/addons/hr_maintenance/models/res_users.py +++ b/addons/hr_maintenance/models/res_users.py @@ -14,7 +14,7 @@ class Users(models.Model): """ init_res = super(Users, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['equipment_count'] + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + ['equipment_count'] return init_res diff --git a/addons/hr_skills/models/res_users.py b/addons/hr_skills/models/res_users.py index febd7afdb3..3ab7926f1d 100644 --- a/addons/hr_skills/models/res_users.py +++ b/addons/hr_skills/models/res_users.py @@ -20,6 +20,6 @@ class User(models.Model): ] init_res = super(User, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + hr_skills_fields - type(self).SELF_WRITEABLE_FIELDS = type(self).SELF_WRITEABLE_FIELDS + hr_skills_fields + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + hr_skills_fields + pool[self._name].SELF_WRITEABLE_FIELDS = pool[self._name].SELF_WRITEABLE_FIELDS + hr_skills_fields return init_res diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index c47b5ef878..f98dd62be7 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -581,7 +581,7 @@ class IrHttp(models.AbstractModel): elif isinstance(exception, QWebException): values.update(qweb_exception=exception) - if type(exception.error) == exceptions.AccessError: + if isinstance(exception.error, exceptions.AccessError): code = 403 elif isinstance(exception, werkzeug.exceptions.HTTPException): diff --git a/addons/im_livechat/models/res_users.py b/addons/im_livechat/models/res_users.py index 45262a8eaf..7a0dc2975f 100644 --- a/addons/im_livechat/models/res_users.py +++ b/addons/im_livechat/models/res_users.py @@ -19,9 +19,9 @@ class Users(models.Model): """ init_res = super(Users, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS) - type(self).SELF_WRITEABLE_FIELDS.extend(['livechat_username']) + pool[self._name].SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS) + pool[self._name].SELF_WRITEABLE_FIELDS.extend(['livechat_username']) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS) - type(self).SELF_READABLE_FIELDS.extend(['livechat_username']) + pool[self._name].SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS) + pool[self._name].SELF_READABLE_FIELDS.extend(['livechat_username']) return init_res diff --git a/addons/link_tracker/models/link_tracker.py b/addons/link_tracker/models/link_tracker.py index d386e9cada..8950c91485 100644 --- a/addons/link_tracker/models/link_tracker.py +++ b/addons/link_tracker/models/link_tracker.py @@ -100,7 +100,7 @@ class LinkTracker(models.Model): utms = {} for key, field_name, cook in self.env['utm.mixin'].tracking_fields(): field = self._fields[field_name] - attr = getattr(tracker, field_name) + attr = tracker[field_name] if field.type == 'many2one': attr = attr.name if attr: diff --git a/addons/mail/models/ir_model.py b/addons/mail/models/ir_model.py index 66c55d14c7..9b56d335f7 100644 --- a/addons/mail/models/ir_model.py +++ b/addons/mail/models/ir_model.py @@ -87,9 +87,9 @@ class IrModel(models.Model): def _reflect_model_params(self, model): vals = super(IrModel, self)._reflect_model_params(model) - vals['is_mail_thread'] = issubclass(type(model), self.pool['mail.thread']) - vals['is_mail_activity'] = issubclass(type(model), self.pool['mail.activity.mixin']) - vals['is_mail_blacklist'] = issubclass(type(model), self.pool['mail.thread.blacklist']) + vals['is_mail_thread'] = isinstance(model, self.pool['mail.thread']) + vals['is_mail_activity'] = isinstance(model, self.pool['mail.activity.mixin']) + vals['is_mail_blacklist'] = isinstance(model, self.pool['mail.thread.blacklist']) return vals @api.model diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index c7616ce1b9..dc5574850e 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -96,9 +96,9 @@ class MailMail(models.Model): def default_get(self, fields): # protection for `default_type` values leaking from menu action context (e.g. for invoices) # To remove when automatic context propagation is removed in web client - if self._context.get('default_type') not in type(self).message_type.base_field.selection: + if self._context.get('default_type') not in self._fields['message_type'].base_field.selection: self = self.with_context(dict(self._context, default_type=None)) - if self._context.get('default_state') not in type(self).state.base_field.selection: + if self._context.get('default_state') not in self._fields['state'].base_field.selection: self = self.with_context(dict(self._context, default_state='outgoing')) return super(MailMail, self).default_get(fields) diff --git a/addons/mail/models/mail_notification.py b/addons/mail/models/mail_notification.py index 73156111d7..ebeff5da20 100644 --- a/addons/mail/models/mail_notification.py +++ b/addons/mail/models/mail_notification.py @@ -77,7 +77,7 @@ class MailNotification(models.Model): def format_failure_reason(self): self.ensure_one() if self.failure_type != 'UNKNOWN': - return dict(type(self).failure_type.selection).get(self.failure_type, _('No Error')) + return dict(self._fields['failure_type'].selection).get(self.failure_type, _('No Error')) else: return _("Unknown error") + ": %s" % (self.failure_reason or '') diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 90c85aa211..f76e1ddb72 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -719,7 +719,7 @@ class MailThread(models.AbstractModel): bounced_record_done = bounced_record_done or (bounced_record and model.model == bounced_model and bounced_record in rec_bounce_w_email) # set record as bounced unless already done due to blacklist mixin - if bounced_record and not bounced_record_done and issubclass(type(bounced_record), self.pool['mail.thread']): + if bounced_record and not bounced_record_done and isinstance(bounced_record, self.pool['mail.thread']): bounced_record._message_receive_bounce(bounced_email, bounced_partner) if bounced_partner and bounced_message: @@ -1642,7 +1642,7 @@ class MailThread(models.AbstractModel): If no partner has been found and/or created for a given emails its matching partner is an empty record. """ - if records and issubclass(type(records), self.pool['mail.thread']): + if records and isinstance(records, self.pool['mail.thread']): followers = records.mapped('message_partner_ids') else: followers = self.env['res.partner'] diff --git a/addons/mail/models/res_users.py b/addons/mail/models/res_users.py index 0b081d7f23..66fc85d8f6 100644 --- a/addons/mail/models/res_users.py +++ b/addons/mail/models/res_users.py @@ -66,11 +66,11 @@ GROUP BY channel_moderator.res_users_id""", [tuple(self.ids)]) """ init_res = super(Users, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS) - type(self).SELF_WRITEABLE_FIELDS.extend(['notification_type']) + pool[self._name].SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS) + pool[self._name].SELF_WRITEABLE_FIELDS.extend(['notification_type']) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS) - type(self).SELF_READABLE_FIELDS.extend(['notification_type']) + pool[self._name].SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS) + pool[self._name].SELF_READABLE_FIELDS.extend(['notification_type']) return init_res @api.model_create_multi diff --git a/addons/mail/wizard/mail_compose_message.py b/addons/mail/wizard/mail_compose_message.py index b395364698..3e43bd8b3a 100644 --- a/addons/mail/wizard/mail_compose_message.py +++ b/addons/mail/wizard/mail_compose_message.py @@ -288,7 +288,7 @@ class MailComposer(models.TransientModel): reply_to_value[res_id] = rendered_values.get(res_id, {}).get('email_from', False) blacklisted_rec_ids = set() - if mass_mail_mode and issubclass(type(self.env[self.model]), self.pool['mail.thread.blacklist']): + if mass_mail_mode and isinstance(self.env[self.model], self.pool['mail.thread.blacklist']): self.env['mail.blacklist'].flush(['email']) self._cr.execute("SELECT email FROM mail_blacklist WHERE active=true") blacklist = {x[0] for x in self._cr.fetchall()} diff --git a/addons/mail_bot/models/res_users.py b/addons/mail_bot/models/res_users.py index 4bf5006639..0adc27de5e 100644 --- a/addons/mail_bot/models/res_users.py +++ b/addons/mail_bot/models/res_users.py @@ -25,5 +25,5 @@ class Users(models.Model): """ init_res = super(Users, self).__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['flectrabot_state'] + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + ['flectrabot_state'] return init_res diff --git a/addons/mass_mailing/models/mail_thread.py b/addons/mass_mailing/models/mail_thread.py index e71c0df7ac..76acd6e945 100644 --- a/addons/mass_mailing/models/mail_thread.py +++ b/addons/mass_mailing/models/mail_thread.py @@ -71,7 +71,7 @@ class MailThread(models.AbstractModel): """ defaults = {} - if issubclass(type(self), self.pool['utm.mixin']): + if isinstance(self, self.pool['utm.mixin']): thread_references = msg_dict.get('references', '') or msg_dict.get('in_reply_to', '') msg_references = tools.mail_header_msgid_re.findall(thread_references) if msg_references: diff --git a/addons/mass_mailing/models/mailing.py b/addons/mass_mailing/models/mailing.py index d5be702d9e..2006d36d33 100644 --- a/addons/mass_mailing/models/mailing.py +++ b/addons/mass_mailing/models/mailing.py @@ -293,7 +293,7 @@ class MassMailing(models.Model): return super(MassMailing, self).copy(default=default) def _group_expand_states(self, states, domain, order): - return [key for key, val in type(self).state.selection] + return [key for key, val in self._fields['state'].selection] # ------------------------------------------------------ # ACTIONS diff --git a/addons/mass_mailing_sms/models/mailing_mailing.py b/addons/mass_mailing_sms/models/mailing_mailing.py index 32952e25b1..40591cae4b 100644 --- a/addons/mass_mailing_sms/models/mailing_mailing.py +++ b/addons/mass_mailing_sms/models/mailing_mailing.py @@ -181,9 +181,9 @@ class Mailing(models.Model): target = self.env[self.mailing_model_real] partner_fields = [] - if issubclass(type(target), self.pool['mail.thread.phone']): + if isinstance(target, self.pool['mail.thread.phone']): phone_fields = ['phone_sanitized'] - elif issubclass(type(target), self.pool['mail.thread']): + elif isinstance(target, self.pool['mail.thread']): phone_fields = [ fname for fname in target._sms_get_number_fields() if fname in target._fields and target._fields[fname].store diff --git a/addons/microsoft_outlook/controllers/main.py b/addons/microsoft_outlook/controllers/main.py index 9c49d4cda9..ce74e3528d 100644 --- a/addons/microsoft_outlook/controllers/main.py +++ b/addons/microsoft_outlook/controllers/main.py @@ -46,7 +46,7 @@ class MicrosoftOutlookController(http.Controller): model = request.env[model_name] - if not issubclass(type(model), request.env.registry['microsoft.outlook.mixin']): + if not isinstance(model, request.env.registry['microsoft.outlook.mixin']): # The model must inherits from the "microsoft.outlook.mixin" mixin raise Forbidden() diff --git a/addons/portal/controllers/mail.py b/addons/portal/controllers/mail.py index 4583436e44..6ef9160abd 100644 --- a/addons/portal/controllers/mail.py +++ b/addons/portal/controllers/mail.py @@ -234,7 +234,7 @@ class MailController(MailController): if not model or not res_id or model not in request.env: return super(MailController, cls)._redirect_to_record(model, res_id, access_token=access_token, **kwargs) - if issubclass(type(request.env[model]), request.env.registry['portal.mixin']): + if isinstance(request.env[model], request.env.registry['portal.mixin']): uid = request.session.uid or request.env.ref('base.public_user').id record_sudo = request.env[model].sudo().browse(res_id).exists() try: diff --git a/addons/portal/controllers/portal.py b/addons/portal/controllers/portal.py index 0bf2574b4b..56436cd5ec 100644 --- a/addons/portal/controllers/portal.py +++ b/addons/portal/controllers/portal.py @@ -424,7 +424,7 @@ class CustomerPortal(Controller): report_sudo = request.env.ref(report_ref).with_user(SUPERUSER_ID) - if not isinstance(report_sudo, type(request.env['ir.actions.report'])): + if not isinstance(report_sudo, request.env.registry['ir.actions.report']): raise UserError(_("%s is not the reference of a report", report_ref)) if hasattr(model, 'company_id'): diff --git a/addons/sale_stock/models/res_users.py b/addons/sale_stock/models/res_users.py index 30d2181b43..ebafac0cec 100644 --- a/addons/sale_stock/models/res_users.py +++ b/addons/sale_stock/models/res_users.py @@ -28,6 +28,6 @@ class Users(models.Model): init_res = super().__init__(pool, cr) # duplicate list to avoid modifying the original reference - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + sale_stock_writeable_fields - type(self).SELF_WRITEABLE_FIELDS = type(self).SELF_WRITEABLE_FIELDS + sale_stock_writeable_fields + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + sale_stock_writeable_fields + pool[self._name].SELF_WRITEABLE_FIELDS = pool[self._name].SELF_WRITEABLE_FIELDS + sale_stock_writeable_fields return init_res diff --git a/addons/sms/wizard/sms_composer.py b/addons/sms/wizard/sms_composer.py index c9157f1de9..4363c1f9a3 100644 --- a/addons/sms/wizard/sms_composer.py +++ b/addons/sms/wizard/sms_composer.py @@ -107,7 +107,7 @@ class SendSMS(models.TransientModel): continue records = composer._get_records() - if records and issubclass(type(records), self.pool['mail.thread']): + if records and isinstance(records, self.pool['mail.thread']): res = records._sms_get_recipients_info(force_field=composer.number_field_name, partner_fallback=not composer.comment_single_recipient) composer.recipient_valid_count = len([rid for rid, rvalues in res.items() if rvalues['sanitized']]) composer.recipient_invalid_count = len([rid for rid, rvalues in res.items() if not rvalues['sanitized']]) @@ -120,7 +120,7 @@ class SendSMS(models.TransientModel): def _compute_recipient_single(self): for composer in self: records = composer._get_records() - if not records or not issubclass(type(records), self.pool['mail.thread']) or not composer.comment_single_recipient: + if not records or not isinstance(records, self.pool['mail.thread']) or not composer.comment_single_recipient: composer.recipient_single_description = False composer.recipient_single_number = '' composer.recipient_single_number_itf = '' @@ -207,7 +207,7 @@ class SendSMS(models.TransientModel): if self.composition_mode == 'numbers': return self._action_send_sms_numbers() elif self.composition_mode == 'comment': - if records is None or not issubclass(type(records), self.pool['mail.thread']): + if records is None or not isinstance(records, self.pool['mail.thread']): return self._action_send_sms_numbers() if self.comment_single_recipient: return self._action_send_sms_comment_single(records) @@ -257,7 +257,7 @@ class SendSMS(models.TransientModel): sms_record_values = self._prepare_mass_sms_values(records) sms_all = self._prepare_mass_sms(records, sms_record_values) - if sms_all and self.mass_keep_log and records and issubclass(type(records), self.pool['mail.thread']): + if sms_all and self.mass_keep_log and records and isinstance(records, self.pool['mail.thread']): log_values = self._prepare_mass_log_values(records, sms_record_values) records._message_log_batch(**log_values) diff --git a/addons/web/models/base_document_layout.py b/addons/web/models/base_document_layout.py index 030a6c41e5..3c5314c0ba 100644 --- a/addons/web/models/base_document_layout.py +++ b/addons/web/models/base_document_layout.py @@ -171,7 +171,7 @@ class BaseDocumentLayout(models.TransientModel): return False, False # The "===" gives different base64 encoding a correct padding - logo += b'===' if type(logo) == bytes else '===' + logo += b'===' if isinstance(logo, bytes) else '===' try: # Catches exceptions caused by logo not being an image image = tools.image_fix_orientation(tools.base64_to_image(logo)) diff --git a/addons/web/models/ir_qweb.py b/addons/web/models/ir_qweb.py index a191ad0c4b..3440594ef6 100644 --- a/addons/web/models/ir_qweb.py +++ b/addons/web/models/ir_qweb.py @@ -38,7 +38,7 @@ class Image(models.AbstractModel): sha = hashlib.sha512(str(getattr(record, '__last_update')).encode('utf-8')).hexdigest()[:7] max_size = '' if max_size is None else '/%s' % max_size - if options.get('filename-field') and getattr(record, options['filename-field'], None): + if options.get('filename-field') and options['filename-field'] in record and record[options['filename-field']]: filename = record[options['filename-field']] elif options.get('filename'): filename = options['filename'] @@ -72,7 +72,7 @@ class Image(models.AbstractModel): src, src_zoom = self._get_src_urls(record, field_name, options) - if options.get('alt-field') and getattr(record, options['alt-field'], None): + if options.get('alt-field') and options['alt-field'] in record and record[options['alt-field']]: alt = escape(record[options['alt-field']]) elif options.get('alt'): alt = options['alt'] diff --git a/addons/web/models/models.py b/addons/web/models/models.py index 837a75e24a..42a31a9912 100644 --- a/addons/web/models/models.py +++ b/addons/web/models/models.py @@ -160,7 +160,7 @@ class Base(models.AbstractModel): def adapt(value): if field_type == 'selection': value = selection_labels.get(value, False) - if type(value) == tuple: + if isinstance(value, tuple): value = value[1] # FIXME should use technical value (0) return value diff --git a/addons/web_editor/models/ir_qweb.py b/addons/web_editor/models/ir_qweb.py index 71a25945e9..875df5408d 100644 --- a/addons/web_editor/models/ir_qweb.py +++ b/addons/web_editor/models/ir_qweb.py @@ -199,7 +199,7 @@ class ManyToOne(models.AbstractModel): def attributes(self, record, field_name, options, values): attrs = super(ManyToOne, self).attributes(record, field_name, options, values) if options.get('inherit_branding'): - many2one = getattr(record, field_name) + many2one = record[field_name] if many2one: attrs['data-oe-many2one-id'] = many2one.id attrs['data-oe-many2one-model'] = many2one._name diff --git a/addons/website_profile/controllers/main.py b/addons/website_profile/controllers/main.py index 42aeecdac3..5ef5bc1045 100644 --- a/addons/website_profile/controllers/main.py +++ b/addons/website_profile/controllers/main.py @@ -163,7 +163,7 @@ class WebsiteProfile(http.Controller): else: user = request.env.user values = self._profile_edition_preprocess_values(user, **kwargs) - whitelisted_values = {key: values[key] for key in type(user).SELF_WRITEABLE_FIELDS if key in values} + whitelisted_values = {key: values[key] for key in request.env.registry['res.users'].SELF_WRITEABLE_FIELDS if key in values} user.write(whitelisted_values) if kwargs.get('url_param'): return werkzeug.utils.redirect("/profile/user/%d?%s" % (user.id, kwargs['url_param'])) diff --git a/addons/website_profile/models/res_users.py b/addons/website_profile/models/res_users.py index 59de25c4cc..27c8e79759 100644 --- a/addons/website_profile/models/res_users.py +++ b/addons/website_profile/models/res_users.py @@ -16,11 +16,11 @@ class Users(models.Model): def __init__(self, pool, cr): init_res = super(Users, self).__init__(pool, cr) - type(self).SELF_WRITEABLE_FIELDS = list( + pool[self._name].SELF_WRITEABLE_FIELDS = list( set( self.SELF_WRITEABLE_FIELDS + ['country_id', 'city', 'website', 'website_description', 'website_published'])) - type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['karma'] + pool[self._name].SELF_READABLE_FIELDS = pool[self._name].SELF_READABLE_FIELDS + ['karma'] return init_res @api.model