# Copyright 2026 Criptomart
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class ProjectProject(models.Model):
    _inherit = "project.project"

    def write(self, vals):
        res = super().write(vals)
        if "analytic_account_id" in vals:
            self.env["project.task"].with_context(active_test=False).search(
                [("project_id", "in", self.ids)]
            ).write({"analytic_account_id": vals["analytic_account_id"]})
        return res

    # No need to override _create_analytic_account: the core method already
    # calls project.write({'analytic_account_id': ...}) which triggers our
    # write() override above and propagates the account to all tasks.
