Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][FIX] partner_company_default #1639

Merged
merged 1 commit into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions partner_company_default/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.tools import config


class ResPartner(models.Model):
_inherit = "res.partner"

company_id = fields.Many2one(default=lambda self: self.env.company)
company_id = fields.Many2one(default=lambda self: self._default_company_id())

@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)
def _default_company_id(self):
"""Return False for other tests or if creating a company."""
context = self.env.context
if (
context.get("creating_from_company")
or config["test_enable"]
and not context.get("test_partner_company_default")
):
return False
return self.env.company
2 changes: 2 additions & 0 deletions partner_company_default/tests/test_partner_company_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def test_partner_company_default(self):
partner = (
self.env["res.partner"]
.with_user(self.user.id)
.with_context(test_partner_company_default=True)
.create({"name": "Test Partner 1"})
)
self.assertEqual(partner.company_id, self.user.company_id)
Expand All @@ -39,6 +40,7 @@ def test_partner_company_default(self):
partner = (
self.env["res.partner"]
.with_user(self.user.id)
.with_context(test_partner_company_default=True)
.create({"name": "Test Partner 2"})
)
self.assertEqual(partner.company_id, company_fr)
Loading