[FIX] project: check company

Steps to reproduce:
- Install Stock and Project
- Create a new proect with current company as customer
(3 dots menu on project overview to the customer)
- Create a new warehouse for the current company
- Error pops

Bug:
since commit[1] check company is enforced on the project_id field of
partners in bothways
when creating a new warehouse CheckCompany fields are editted on the
partner if set (property_stock_customer/supplier) the issue is if
the partner's company_id is False while project belongs to company
"_check_company" fails

Fix:
Remove check company on project_ids from the partner's side and
implement it as python constraint

opw-3507952
[1]:https://github.com/odoo/odoo/pull/109464

closes odoo/odoo#143679

X-original-commit: 3741557dc4b5e84876247db851e9d2c862fcb93b
Signed-off-by: Xavier Bol (xbo) <xbo@odoo.com>
Signed-off-by: Walid Hanniche (waha) <waha@odoo.com>
This commit is contained in:
Walid
2023-11-27 21:39:18 +00:00
parent ef5afda076
commit 390807c494
5 changed files with 57 additions and 8 deletions
+14
View File
@@ -3172,6 +3172,20 @@ msgid ""
"People invited to collaborate on the project will have portal access rights."
msgstr ""
#. module: project
#. odoo-python
#: code:addons/project/models/res_partner.py:0
#, python-format
msgid "Partner company cannot be different from its assigned projects' company"
msgstr ""
#. module: project
#. odoo-python
#: code:addons/project/models/res_partner.py:0
#, python-format
msgid "Partner company cannot be different from its assigned tasks' company"
msgstr ""
#. module: project
#: model:ir.model.fields,help:project.field_project_project__privacy_visibility
#: model:ir.model.fields,help:project.field_project_task__project_privacy_visibility
+16 -4
View File
@@ -1,19 +1,31 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from odoo.tools import email_normalize
class ResPartner(models.Model):
""" Inherits partner and adds Tasks information in the partner form """
_inherit = 'res.partner'
_check_company_auto = True
project_ids = fields.One2many('project.project', 'partner_id', string='Projects', check_company=True)
task_ids = fields.One2many('project.task', 'partner_id', string='Tasks', check_company=True)
project_ids = fields.One2many('project.project', 'partner_id', string='Projects')
task_ids = fields.One2many('project.task', 'partner_id', string='Tasks')
task_count = fields.Integer(compute='_compute_task_count', string='# Tasks')
@api.constrains('company_id', 'project_ids')
def _ensure_same_company_than_projects(self):
for partner in self:
if partner.company_id and partner.project_ids.company_id and partner.project_ids.company_id != partner.company_id:
raise UserError(_("Partner company cannot be different from its assigned projects' company"))
@api.constrains('company_id', 'task_ids')
def _ensure_same_company_than_tasks(self):
for partner in self:
if partner.company_id and partner.task_ids.company_id and partner.task_ids.company_id != partner.company_id:
raise UserError(_("Partner company cannot be different from its assigned tasks' company"))
def _compute_task_count(self):
# retrieve all children partners and prefetch 'parent_id' on them
all_partners = self.with_context(active_test=False).search_fetch(
+7 -4
View File
@@ -214,13 +214,16 @@ class TestProjectBase(TestProjectCommon):
with self.assertRaises(UserError):
# Cannot change the company of a partner if both the project and its partner have a company
partner.company_id = company_2
with self.assertRaises(UserError):
# Cannot set the company of a partner to False if both the project and its partner have a company
partner.company_id = False
partner.company_id = False
self.project_pigs.company_id = False
self.assertFalse(self.project_pigs.company_id, "The company of the project should have been set to False.")
partner.company_id = False
self.project_pigs.company_id = company_1
self.project_goats.company_id = company_1
self.project_goats.partner_id = partner
with self.assertRaises(UserError):
# Cannot change the company of a partner that part of multiple projects with different companies
self.project_goats.partner_id.company_id = company_2
# The project has a company, but the partner has none. The partner can only be set to False/project.company but the project can have any new company.
with self.assertRaises(UserError):
+1
View File
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import test_project_profitability
from . import test_project_stock
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.project.tests.test_project_base import TestProjectCommon
class TestProjectStock(TestProjectCommon):
def test_check_company(self):
"""
tests editing relation fields of a partner from a project
"""
self.project_pigs.partner_id = self.env['res.partner'].create({
'name': 'Jeff Delaney',
})
self.env['stock.warehouse'].create({
'name': 'Hi mom!',
'partner_id': self.project_pigs.partner_id.id,
'code': 'Fireship',
})