<commit_before># -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, models


class ModuleUpgrade(models.TransientModel):
    _inherit = 'base.module.upgrade'

    @api.model
    def get_module_list(self):
        if not self.env.context.get('module_uninstall'):
            Module = self.env["ir.module.module"]
            installed_modules = Module.search([('state', '=', 'installed')])
            upgradeable_modules = installed_modules.filtered(
                lambda r: r.checksum_dir != r.checksum_installed,
            )
            upgradeable_modules.button_upgrade()
        return super(ModuleUpgrade, self).get_module_list()

    @api.multi
    def upgrade_module_cancel(self):
        return super(
            ModuleUpgrade,
            self.with_context(retain_checksum_installed=True),
        ).upgrade_module_cancel()

    @api.multi
    def upgrade_module(self):
        # Compute updates by checksum when called in @api.model fashion
        if not self:
            self.get_module_list()
        # Get base adddon status before updating
        base = self.env["ir.module.module"].search([("name", "=", "base")])
        pre_state = base.state
        result = super(ModuleUpgrade, self).upgrade_module()
        # Update base addon checksum if its state changed
        base.invalidate_cache()
        if base.state != pre_state:
            # This triggers the write hook that should have been triggered
            # when the module was [un]installed/updated in the base-only
            # module graph inside above call to super(), and updates its
            # dir checksum as needed
            base.latest_version = base.latest_version
        return result<commit_msg>[FIX][module_auto_update] Always store changes in lower graphs<commit_after># -*- coding: utf-8 -*-
# Copyright 2017 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, models


class ModuleUpgrade(models.TransientModel):
    _inherit = 'base.module.upgrade'

    @api.model
    def get_module_list(self):
        """Set modules to upgrade searching by their dir checksum."""
        Module = self.env["ir.module.module"]
        installed_modules = Module.search([('state', '=', 'installed')])
        upgradeable_modules = installed_modules.filtered(
            lambda r: r.checksum_dir != r.checksum_installed,
        )
        upgradeable_modules.button_upgrade()
        return super(ModuleUpgrade, self).get_module_list()

    @api.multi
    def upgrade_module(self):
        """Make a fully automated addon upgrade."""
        # Compute updates by checksum when called in @api.model fashion
        if not self:
            self.get_module_list()
        Module = self.env["ir.module.module"]
        # Get every addon state before updating
        pre_states = {addon["name"]: addon["state"]
                      for addon in Module.search_read([], ["name", "state"])}
        # Perform upgrades, possibly in a limited graph that excludes me
        result = super(ModuleUpgrade, self).upgrade_module()
        # Reload environments, anything may have changed
        self.env.clear()
        # Update addons checksum if state changed and I wasn't uninstalled
        own = Module.search_read(
            [("name", "=", "module_auto_update")],
            ["state"],
            limit=1)
        if own and own[0]["state"] != "uninstalled":
            for addon in Module.search([]):
                if addon.state != pre_states.get(addon.name):
                    # Trigger the write hook that should have been
                    # triggered when the module was [un]installed/updated in
                    # the limited module graph inside above call to super(),
                    # and updates its dir checksum as needed
                    addon.latest_version = addon.latest_version
        return result
{'fraction_non_alphanumeric': 0.10269997476659097, 'fraction_numerical': 0.0040373454453696694, 'mean_word_length': 2.3793691389599316, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3738644', 'n_tokens_mistral': 1099, 'n_tokens_neox': 1050, 'n_words': 303}