mirror of
https://github.com/bringout/oca-ocb-project.git
synced 2026-04-21 10:22:04 +02:00
19.0 vanilla
This commit is contained in:
parent
a2f74aefd8
commit
4a4d12c333
844 changed files with 212348 additions and 270090 deletions
|
|
@ -0,0 +1,44 @@
|
|||
# -*- 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', 'account_id', string='Projects', export_string_translation=False)
|
||||
project_count = fields.Integer("Project Count", compute='_compute_project_count', export_string_translation=False)
|
||||
|
||||
@api.depends('project_ids')
|
||||
def _compute_project_count(self):
|
||||
project_data = self.env['project.project']._read_group([('account_id', 'in', self.ids)], ['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):
|
||||
has_tasks = self.env['project.task'].search_count(
|
||||
[('project_id.account_id', 'in', self.ids)],
|
||||
limit=1,
|
||||
)
|
||||
if has_tasks:
|
||||
raise UserError(_("Before we can bid farewell to these accounts, you need to tidy up the projects linked to them by removing their existing tasks!"))
|
||||
|
||||
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": [['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
|
||||
Loading…
Add table
Add a link
Reference in a new issue