summaryrefslogtreecommitdiff
path: root/addons/project/models
diff options
context:
space:
mode:
authorjvm-odoo <jvm@odoo.com>2020-04-22 06:51:15 +0000
committerjvm-odoo <jvm@odoo.com>2020-04-23 08:23:49 +0000
commit9bcfb5c8d8dc2296a37b9b99ec1a0ea771d53977 (patch)
tree8eff6387b6e94ec9b4f7237b06db9add8261edbb /addons/project/models
parent2d002631273ae11a788dc9826d0c913eb705479e (diff)
[FIX] project: prevent changing company_id of an analytic account
Issue - Have 2 company - Install Timesheet, Accounting, Project - Enable analytic accounting - Accounting > Settings > Analytic accounts - Remove the company_id of one of them which is linked to a project - Timesheet > add a line for this project Error Cause Timesheets lines are linked to a company and a project Removing the company_id of the project's analytic account create an inconsistency Solution Prevent changing the company_id of an analytic account which is linked to a project. OPW-2233266 closes odoo/odoo#50039 X-original-commit: 4895fb5029f492faf31b28b648e56ded8b3a83fb Signed-off-by: Jason Van Malder (jvm) <jvm@odoo.com>
Diffstat (limited to 'addons/project/models')
-rw-r--r--addons/project/models/analytic_account.py6
1 files changed, 6 insertions, 0 deletions
diff --git a/addons/project/models/analytic_account.py b/addons/project/models/analytic_account.py
index 794f882c318..5ff33265efa 100644
--- a/addons/project/models/analytic_account.py
+++ b/addons/project/models/analytic_account.py
@@ -19,6 +19,12 @@ class AccountAnalyticAccount(models.Model):
for account in self:
account.project_count = mapping.get(account.id, 0)
+ @api.constrains('company_id')
+ def _check_company_id(self):
+ for record in self:
+ if record.project_ids:
+ raise UserError(_('You cannot change the company of an analytical account if it is related to a project.'))
+
def unlink(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)])