Files
odoo_source/addons/project/models/account_analytic_account.py
T
damr 16a07ed1bf [IMP] project: make the field company_id of projects non required
This commit's purpose is to allow the user to set the company_id of a project to False, meaning the project is no longer restricted for the user who does not have access to the company of the project. This change induces a lot of other small behavior changes/approximation. Since some fields (currency_id, resource_calendar_id, etc) were company dependent, we had to updates some use cases.

task-3084819

closes odoo/odoo#122144

Related: odoo/enterprise#41363
Related: odoo/upgrade#4947
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
2023-07-19 23:17:53 +02:00

43 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class AccountAnalyticAccount(models.Model):
_inherit = 'account.analytic.account'
_description = 'Analytic Account'
project_ids = fields.One2many('project.project', 'analytic_account_id', string='Projects')
project_count = fields.Integer("Project Count", compute='_compute_project_count')
@api.depends('project_ids')
def _compute_project_count(self):
project_data = self.env['project.project']._read_group([('analytic_account_id', 'in', self.ids)], ['analytic_account_id'], ['__count'])
mapping = {analytic_account.id: count for analytic_account, count in project_data}
for account in self:
account.project_count = mapping.get(account.id, 0)
@api.ondelete(at_uninstall=False)
def _unlink_except_existing_tasks(self):
projects = self.env['project.project'].search([('analytic_account_id', 'in', self.ids)])
has_tasks = self.env['project.task'].search_count([('project_id', 'in', projects.ids)])
if has_tasks:
raise UserError(_('Please remove existing tasks in the project linked to the accounts you want to delete.'))
def action_view_projects(self):
kanban_view_id = self.env.ref('project.view_project_kanban').id
result = {
"type": "ir.actions.act_window",
"res_model": "project.project",
"views": [[kanban_view_id, "kanban"], [False, "form"]],
"domain": [['analytic_account_id', '=', self.id]],
"context": {"create": False},
"name": _("Projects"),
}
if len(self.project_ids) == 1:
result['views'] = [(False, "form")]
result['res_id'] = self.project_ids.id
return result