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

[FIX] shopinvader: res.config.settings - no_partner_duplicate #5

Open
wants to merge 1 commit into
base: 14.0-fix-auth-for-setting
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion shopinvader/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class ResConfigSettings(models.TransientModel):

shopinvader_no_partner_duplicate = fields.Boolean(
string="No partner duplicate",
default=True,
config_parameter="shopinvader.no_partner_duplicate",
help="If checked, when a binding is created for a backend, we first "
"try to find a partner with the same email and if found we link "
Expand Down
11 changes: 3 additions & 8 deletions shopinvader/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ class ResPartner(models.Model):
)

@api.model
def _is_partner_duplicate_allowed(self):
"""Check if partner duplication is allowed

This parameter is configured through res.config.settings
"""
def _is_partner_duplicate_prevented(self):
get_param = self.env["ir.config_parameter"].sudo().get_param
param = get_param("shopinvader.no_partner_duplicate")
return not str2bool(param, True)
return str2bool(get_param("shopinvader.no_partner_duplicate"))

@api.depends("is_blacklisted")
def _compute_opt_in(self):
Expand Down Expand Up @@ -88,7 +83,7 @@ def _compute_address_type(self):

@api.constrains("email")
def _check_unique_email(self):
if self._is_partner_duplicate_allowed():
if not self._is_partner_duplicate_prevented():
return True
self.env.cr.execute(
"""
Expand Down
2 changes: 1 addition & 1 deletion shopinvader/models/shopinvader_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _prepare_create_params(self, vals):
@api.model
def _get_or_create_partner(self, vals):
partner = self.env["res.partner"].browse()
if not partner._is_partner_duplicate_allowed():
if partner._is_partner_duplicate_prevented():
domain = self._get_unique_partner_domain(vals)
partner = partner.search(domain, limit=1)
if partner:
Expand Down
4 changes: 2 additions & 2 deletions shopinvader/tests/test_res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def setUpClass(cls):
cls.unique_email = datetime.now().isoformat() + "@test.com"

def test_unique_email_partner(self):
self.assertTrue(self.env["res.partner"]._is_partner_duplicate_allowed())
self.assertFalse(self.env["res.partner"]._is_partner_duplicate_prevented())
partner_1 = self.env["res.partner"].create(
{"email": self.unique_email, "name": "test partner"}
)
Expand All @@ -27,7 +27,7 @@ def test_unique_email_partner(self):
self.env["ir.config_parameter"].create(
{"key": "shopinvader.no_partner_duplicate", "value": "True"}
)
self.assertFalse(self.env["res.partner"]._is_partner_duplicate_allowed())
self.assertTrue(self.env["res.partner"]._is_partner_duplicate_prevented())
# once you've changed the config to dispable duplicate partner
# it's no more possible to create a partner with the same email
with self.assertRaises(ValidationError), self.cr.savepoint():
Expand Down
6 changes: 3 additions & 3 deletions shopinvader/tests/test_shopinvader_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_partner_duplicate(self):
email (after having removed the first binding)
:return:
"""
self.assertTrue(self.env["res.partner"]._is_partner_duplicate_allowed())
self.assertFalse(self.env["res.partner"]._is_partner_duplicate_prevented())
# we create a first binding
binding = self.env["shopinvader.partner"].create(
{
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_partner_no_duplicate(self):
self.env["ir.config_parameter"].create(
{"key": "shopinvader.no_partner_duplicate", "value": "True"}
)
self.assertFalse(self.env["res.partner"]._is_partner_duplicate_allowed())
self.assertTrue(self.env["res.partner"]._is_partner_duplicate_prevented())
vals = {"email": self.unique_email, "name": "test partner"}
# create a partner...
partner = self.env["res.partner"].create(vals)
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_partner_no_duplicate_child(self):
self.env["ir.config_parameter"].create(
{"key": "shopinvader.no_partner_duplicate", "value": "True"}
)
self.assertFalse(self.env["res.partner"]._is_partner_duplicate_allowed())
self.assertTrue(self.env["res.partner"]._is_partner_duplicate_prevented())
vals = {"email": self.unique_email, "name": "test partner"}
# create a partner...
partner = self.env["res.partner"].create(vals)
Expand Down