Browse Source
[MIG] partner_fistname: Migration to 13.0
[MIG] partner_fistname: Migration to 13.0
Remove kack on context and pseudo onchange methods and takes benefit on compute method with readonly=False14.0
Laurent Mignon (ACSONE)
5 years ago
committed by
Luis Torres
11 changed files with 174 additions and 200 deletions
-
3partner_firstname/exceptions.py
-
31partner_firstname/models/res_partner.py
-
1partner_firstname/readme/CONTRIBUTORS.rst
-
4partner_firstname/tests/__init__.py
-
12partner_firstname/tests/base.py
-
2partner_firstname/tests/test_name.py
-
104partner_firstname/tests/test_onchange.py
-
103partner_firstname/tests/test_partner_form.py
-
59partner_firstname/tests/test_user_form.py
-
51partner_firstname/tests/test_user_onchange.py
-
4partner_firstname/views/base_config_view.xml
@ -1,104 +0,0 @@ |
|||
# Copyright 2015 Grupo ESOC <www.grupoesoc.es> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
"""These tests try to mimic the behavior of the UI form. |
|||
|
|||
The form operates in onchange mode, with its limitations. |
|||
""" |
|||
|
|||
from .base import OnChangeCase |
|||
|
|||
|
|||
class PartnerCompanyCase(OnChangeCase): |
|||
is_company = True |
|||
|
|||
def test_create_from_form(self): |
|||
"""A user creates a company from the form.""" |
|||
name = "Sôme company" |
|||
with self.env.do_in_onchange(): |
|||
# User presses ``new`` |
|||
partner = self.new_partner() |
|||
|
|||
# User sets a name, which triggers onchanges |
|||
partner.name = name |
|||
partner._onchange_name() |
|||
|
|||
self.assertEqual(partner.name, name) |
|||
self.assertEqual(partner.firstname, False) |
|||
self.assertEqual(partner.lastname, name) |
|||
|
|||
def test_empty_name_and_subnames(self): |
|||
"""If the user empties ``name``, subnames must be ``False``. |
|||
|
|||
Otherwise, the ``required`` attr will not work as expected. |
|||
""" |
|||
with self.env.do_in_onchange(): |
|||
# User presses ``new`` |
|||
partner = self.new_partner() |
|||
|
|||
# User sets a name, which triggers onchanges |
|||
partner.name = "Foó" |
|||
partner._onchange_name() |
|||
|
|||
# User unsets name, which triggers onchanges |
|||
partner.name = "" |
|||
partner._onchange_name() |
|||
|
|||
self.assertEqual(partner.firstname, False) |
|||
self.assertEqual(partner.lastname, False) |
|||
|
|||
|
|||
class PartnerContactCase(OnChangeCase): |
|||
def test_create_from_form_only_firstname(self): |
|||
"""A user creates a contact with only the firstname from the form.""" |
|||
firstname = "Fïrst" |
|||
with self.env.do_in_onchange(): |
|||
# User presses ``new`` |
|||
partner = self.new_partner() |
|||
|
|||
# Changes firstname, which triggers onchanges |
|||
partner.firstname = firstname |
|||
partner._onchange_subnames() |
|||
partner._onchange_name() |
|||
|
|||
self.assertEqual(partner.lastname, False) |
|||
self.assertEqual(partner.firstname, firstname) |
|||
self.assertEqual(partner.name, firstname) |
|||
|
|||
def test_create_from_form_only_lastname(self): |
|||
"""A user creates a contact with only the lastname from the form.""" |
|||
lastname = "Läst" |
|||
with self.env.do_in_onchange(): |
|||
# User presses ``new`` |
|||
partner = self.new_partner() |
|||
|
|||
# Changes lastname, which triggers onchanges |
|||
partner.lastname = lastname |
|||
partner._onchange_subnames() |
|||
partner._onchange_name() |
|||
|
|||
self.assertEqual(partner.firstname, False) |
|||
self.assertEqual(partner.lastname, lastname) |
|||
self.assertEqual(partner.name, lastname) |
|||
|
|||
def test_create_from_form_all(self): |
|||
"""A user creates a contact with all names from the form.""" |
|||
firstname = "Fïrst" |
|||
lastname = "Läst" |
|||
with self.env.do_in_onchange(): |
|||
# User presses ``new`` |
|||
partner = self.new_partner() |
|||
|
|||
# Changes firstname, which triggers onchanges |
|||
partner.firstname = firstname |
|||
partner._onchange_subnames() |
|||
partner._onchange_name() |
|||
|
|||
# Changes lastname, which triggers onchanges |
|||
partner.lastname = lastname |
|||
partner._onchange_subnames() |
|||
partner._onchange_name() |
|||
|
|||
self.assertEqual(partner.lastname, lastname) |
|||
self.assertEqual(partner.firstname, firstname) |
|||
self.assertEqual(partner.name, " ".join((firstname, lastname))) |
@ -0,0 +1,103 @@ |
|||
# Copyright 2015 Grupo ESOC <www.grupoesoc.es> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
"""These tests try to mimic the behavior of the UI form. |
|||
|
|||
The form operates in onchange mode, with its limitations. |
|||
""" |
|||
|
|||
from odoo.tests.common import Form, TransactionCase |
|||
|
|||
from ..exceptions import EmptyNamesError |
|||
|
|||
|
|||
class PartnerCompanyCase(TransactionCase): |
|||
is_company = True |
|||
|
|||
def test_create_from_form(self): |
|||
name = "Sôme company" |
|||
with Form(self.env["res.partner"]) as partner_form: |
|||
partner_form.is_company = self.is_company |
|||
partner_form.name = name |
|||
|
|||
self.assertEqual(partner_form.name, name) |
|||
self.assertEqual(partner_form.firstname, False) |
|||
self.assertEqual(partner_form.lastname, name) |
|||
|
|||
def test_empty_name(self): |
|||
"""If we empty the name and save the form, EmptyNamesError must |
|||
be raised (firstname and lastname are reset...) |
|||
""" |
|||
with Form( |
|||
self.env["res.partner"], view="base.view_partner_simple_form" |
|||
) as partner_form: |
|||
partner_form.is_company = self.is_company |
|||
|
|||
name = "Foó" |
|||
# User sets a name |
|||
partner_form.name = name |
|||
# call save to trigger the inverse |
|||
partner_form.save() |
|||
self.assertEqual(partner_form.name, name) |
|||
self.assertEqual(partner_form.firstname, False) |
|||
self.assertEqual(partner_form.lastname, name) |
|||
|
|||
# User unsets name |
|||
partner_form.name = "" |
|||
# call save to trigger the inverse and therefore raise an exception |
|||
with self.assertRaises(EmptyNamesError), self.env.cr.savepoint(): |
|||
partner_form.save() |
|||
|
|||
name += " bis" |
|||
partner_form.name = name |
|||
partner_form.save() |
|||
self.assertEqual(partner_form.name, name) |
|||
self.assertEqual(partner_form.firstname, False) |
|||
self.assertEqual(partner_form.lastname, name) |
|||
|
|||
|
|||
class PartnerContactCase(TransactionCase): |
|||
is_company = False |
|||
|
|||
def test_create_from_form_only_firstname(self): |
|||
"""A user creates a contact with only the firstname from the form.""" |
|||
firstname = "Fïrst" |
|||
with Form(self.env["res.partner"]) as partner_form: |
|||
partner_form.is_company = self.is_company |
|||
|
|||
# Changes firstname, which triggers compute |
|||
partner_form.firstname = firstname |
|||
|
|||
self.assertEqual(partner_form.lastname, False) |
|||
self.assertEqual(partner_form.firstname, firstname) |
|||
self.assertEqual(partner_form.name, firstname) |
|||
|
|||
def test_create_from_form_only_lastname(self): |
|||
"""A user creates a contact with only the lastname from the form.""" |
|||
lastname = "Läst" |
|||
with Form(self.env["res.partner"]) as partner_form: |
|||
partner_form.is_company = self.is_company |
|||
|
|||
# Changes lastname, which triggers compute |
|||
partner_form.lastname = lastname |
|||
|
|||
self.assertEqual(partner_form.firstname, False) |
|||
self.assertEqual(partner_form.lastname, lastname) |
|||
self.assertEqual(partner_form.name, lastname) |
|||
|
|||
def test_create_from_form_all(self): |
|||
"""A user creates a contact with all names from the form.""" |
|||
firstname = "Fïrst" |
|||
lastname = "Läst" |
|||
with Form(self.env["res.partner"]) as partner_form: |
|||
partner_form.is_company = self.is_company |
|||
|
|||
# Changes firstname, which triggers compute |
|||
partner_form.firstname = firstname |
|||
|
|||
# Changes lastname, which triggers compute |
|||
partner_form.lastname = lastname |
|||
|
|||
self.assertEqual(partner_form.lastname, lastname) |
|||
self.assertEqual(partner_form.firstname, firstname) |
|||
self.assertEqual(partner_form.name, " ".join((firstname, lastname))) |
@ -0,0 +1,59 @@ |
|||
# Copyright 2016 Yannick Vaucher (Camptocamp SA) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo.tests.common import Form, TransactionCase |
|||
|
|||
|
|||
class UserOnchangeCase(TransactionCase): |
|||
def test_create_from_form_only_firstname(self): |
|||
"""In a new users form, a user set only the firstname.""" |
|||
login = "Zoë" |
|||
firstname = "Zoë" |
|||
with Form( |
|||
self.env["res.users"], view="partner_firstname.view_users_form" |
|||
) as user_form: |
|||
user_form.login = login |
|||
# Changes firstname, which triggers onchanges |
|||
user_form.firstname = firstname |
|||
|
|||
self.assertEqual(user_form.lastname, False) |
|||
self.assertEqual(user_form.firstname, firstname) |
|||
self.assertEqual(user_form.name, firstname) |
|||
|
|||
def test_create_from_form_only_lastname(self): |
|||
"""In a new user form, a user set only the lastname.""" |
|||
login = "Żywioł" |
|||
lastname = "Żywioł" |
|||
with Form( |
|||
self.env["res.users"], view="partner_firstname.view_users_form" |
|||
) as user_form: |
|||
user_form.login = login |
|||
# Changes lastname, which triggers onchanges |
|||
user_form.lastname = lastname |
|||
|
|||
self.assertEqual(user_form.firstname, False) |
|||
self.assertEqual(user_form.lastname, lastname) |
|||
self.assertEqual(user_form.name, lastname) |
|||
|
|||
def test_create_from_form_all(self): |
|||
"""In a new user form, a user set all names.""" |
|||
login = "Zoë.Żywioł" |
|||
firstname = "Zoë" |
|||
lastname = "Żywioł" |
|||
with Form( |
|||
self.env["res.users"], view="partner_firstname.view_users_form" |
|||
) as user_form: |
|||
user_form.login = login |
|||
# Changes firstname, which triggers onchanges |
|||
user_form.firstname = firstname |
|||
|
|||
# Changes lastname, which triggers onchanges |
|||
user_form.lastname = lastname |
|||
|
|||
self.assertEqual(user_form.lastname, lastname) |
|||
self.assertEqual(user_form.firstname, firstname) |
|||
self.assertEqual(user_form.name, " ".join((firstname, lastname))) |
|||
|
|||
def setUp(self): |
|||
super(UserOnchangeCase, self).setUp() |
|||
self.user = self.env["res.users"].new() |
@ -1,51 +0,0 @@ |
|||
# Copyright 2016 Yannick Vaucher (Camptocamp SA) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo.tests.common import TransactionCase |
|||
|
|||
|
|||
class UserOnchangeCase(TransactionCase): |
|||
def test_create_from_form_only_firstname(self): |
|||
"""In a new users form, a user set only the firstname.""" |
|||
firstname = "Zoë" |
|||
with self.env.do_in_onchange(): |
|||
# Changes firstname, which triggers onchanges |
|||
self.user.firstname = firstname |
|||
self.user._compute_name() |
|||
|
|||
self.assertEqual(self.user.lastname, False) |
|||
self.assertEqual(self.user.firstname, firstname) |
|||
self.assertEqual(self.user.name, firstname) |
|||
|
|||
def test_create_from_form_only_lastname(self): |
|||
"""In a new user form, a user set only the lastname.""" |
|||
lastname = "Żywioł" |
|||
with self.env.do_in_onchange(): |
|||
# Changes lastname, which triggers onchanges |
|||
self.user.lastname = lastname |
|||
self.user._compute_name() |
|||
|
|||
self.assertEqual(self.user.firstname, False) |
|||
self.assertEqual(self.user.lastname, lastname) |
|||
self.assertEqual(self.user.name, lastname) |
|||
|
|||
def test_create_from_form_all(self): |
|||
"""In a new user form, a user set all names.""" |
|||
firstname = "Zoë" |
|||
lastname = "Żywioł" |
|||
with self.env.do_in_onchange(): |
|||
# Changes firstname, which triggers onchanges |
|||
self.user.firstname = firstname |
|||
self.user._compute_name() |
|||
|
|||
# Changes lastname, which triggers onchanges |
|||
self.user.lastname = lastname |
|||
self.user._compute_name() |
|||
|
|||
self.assertEqual(self.user.lastname, lastname) |
|||
self.assertEqual(self.user.firstname, firstname) |
|||
self.assertEqual(self.user.name, " ".join((firstname, lastname))) |
|||
|
|||
def setUp(self): |
|||
super(UserOnchangeCase, self).setUp() |
|||
self.user = self.env["res.users"].new() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue