diff options
| author | Raphael Collet <rco@odoo.com> | 2020-04-02 06:45:54 +0000 |
|---|---|---|
| committer | Raphael Collet <rco@odoo.com> | 2020-04-03 11:40:29 +0000 |
| commit | 9afce4805fc8bac45fdba817488aa867fddff69b (patch) | |
| tree | 665f109f3f9881b7e2e0d56caf1a7d9e5aaf9219 /addons/mail/models | |
| parent | 6eb7d5c6a07f678e1d1adca7137652e0626ea17e (diff) | |
[IMP] core: reflect models, fields and selections in batch
This saves 4.5% of the total installation time.
X-original-commit: 8519064dce975af542ccd30dc14c56b9bb36d07b
Diffstat (limited to 'addons/mail/models')
| -rw-r--r-- | addons/mail/models/ir_model_fields.py | 4 | ||||
| -rw-r--r-- | addons/mail/models/mail_alias_mixin.py | 15 |
2 files changed, 9 insertions, 10 deletions
diff --git a/addons/mail/models/ir_model_fields.py b/addons/mail/models/ir_model_fields.py index e8650ce2d6d..e2bed7af3ea 100644 --- a/addons/mail/models/ir_model_fields.py +++ b/addons/mail/models/ir_model_fields.py @@ -12,11 +12,11 @@ class IrModelField(models.Model): help="If set every modification done to this field is tracked in the chatter. Value is used to order tracking values.", ) - def _reflect_field_params(self, field): + def _reflect_field_params(self, field, model_id): """ Tracking value can be either a boolean enabling tracking mechanism on field, either an integer giving the sequence. Default sequence is set to 100. """ - vals = super(IrModelField, self)._reflect_field_params(field) + vals = super(IrModelField, self)._reflect_field_params(field, model_id) tracking = getattr(field, 'tracking', None) if tracking is True: tracking = 100 diff --git a/addons/mail/models/mail_alias_mixin.py b/addons/mail/models/mail_alias_mixin.py index b8e8091b72e..0a14346f479 100644 --- a/addons/mail/models/mail_alias_mixin.py +++ b/addons/mail/models/mail_alias_mixin.py @@ -53,25 +53,24 @@ class AliasMixin(models.AbstractModel): def _init_column(self, name): """ Create aliases for existing rows. """ super(AliasMixin, self)._init_column(name) - if name != 'alias_id': - return + if name == 'alias_id': + # as 'mail.alias' records refer to 'ir.model' records, create + # aliases after the reflection of models + self.pool.post_init(self._init_column_alias_id) + def _init_column_alias_id(self): # both self and the alias model must be present in 'ir.model' - IM = self.env['ir.model'] - IM._reflect_model(self) - IM._reflect_model(self.env[self.get_alias_model_name({})]) - alias_ctx = { 'alias_model_name': self.get_alias_model_name({}), 'alias_parent_model_name': self._name, } - alias_model = self.env['mail.alias'].sudo().with_context(alias_ctx).browse([]) + alias_model = self.env['mail.alias'].sudo().with_context(alias_ctx) child_ctx = { 'active_test': False, # retrieve all records 'prefetch_fields': False, # do not prefetch fields on records } - child_model = self.sudo().with_context(child_ctx).browse([]) + child_model = self.sudo().with_context(child_ctx) for record in child_model.search([('alias_id', '=', False)]): # create the alias, and link it to the current record |
