-
-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9484888
commit 8475bc7
Showing
5 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import res_company | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright 2023 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, models | ||
|
||
|
||
class ResCompany(models.Model): | ||
_inherit = "res.company" | ||
|
||
@api.model | ||
def create(self, vals): | ||
self = self.with_context(creating_from_company=True) | ||
company = super(ResCompany, self).create(vals) | ||
return company |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
# Copyright 2023 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
company_id = fields.Many2one(default=lambda self: self.env.company) | ||
|
||
@api.model | ||
def create(self, vals): | ||
# The context value is set in the create method of res.company | ||
if self.env.context.get("creating_from_company"): | ||
vals["company_id"] = False | ||
return super(ResPartner, self).create(vals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import test_partner_company_default |
60 changes: 60 additions & 0 deletions
60
partner_company_default/tests/test_partner_company_default.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2023 Quartile Limited | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
import odoo.tests.common as common | ||
|
||
|
||
class TestPartnerCompanyDefault(common.TransactionCase): | ||
def setUp(self): | ||
super(TestPartnerCompanyDefault, self).setUp() | ||
|
||
def test_partner_company_default(self): | ||
user = self.env["res.users"].create( | ||
{ | ||
"name": "Test User", | ||
"login": "Test User", | ||
"email": "test@yourcompany.com", | ||
"groups_id": [ | ||
( | ||
6, | ||
0, | ||
[ | ||
self.env.ref("base.group_system").id, | ||
self.env.ref("base.group_partner_manager").id, | ||
], | ||
) | ||
], | ||
} | ||
) | ||
|
||
# Test created partner company | ||
partner = ( | ||
self.env["res.partner"] | ||
.with_user(user.id) | ||
.create({"name": "Test Partner 1"}) | ||
) | ||
self.assertEqual(partner.company_id, user.company_id) | ||
|
||
# Test partners of multi company | ||
company_fr = ( | ||
self.env["res.company"] | ||
.with_user(user.id) | ||
.create( | ||
{ | ||
"name": "French company", | ||
"currency_id": self.env.ref("base.EUR").id, | ||
"country_id": self.env.ref("base.fr").id, | ||
} | ||
) | ||
) | ||
self.assertFalse(company_fr.partner_id.company_id) | ||
|
||
user.company_ids = [(4, company_fr.id)] | ||
user.company_id = company_fr.id | ||
partner = ( | ||
self.env["res.partner"] | ||
.with_user(user.id) | ||
.create({"name": "Test Partner 2"}) | ||
) | ||
|
||
self.assertEqual(partner.company_id, company_fr) |