[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>
This commit is contained in:
jvm-odoo
2020-04-23 08:23:49 +00:00
parent 2d00263127
commit 9bcfb5c8d8
2 changed files with 14 additions and 0 deletions
+8
View File
@@ -3210,6 +3210,14 @@ msgid ""
" and purpose of the stage."
msgstr ""
#. module: project
#: code:addons/project/models/analytic_account.py:0
#, python-format
msgid ""
"You cannot change the company of an analytical account if it is related to a"
" project."
msgstr ""
#. module: project
#: code:addons/project/models/project.py:0
#, python-format
@@ -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)])