Browse Source

[MIG] partner_firstname: Black, isort

14.0
Laurent Mignon (ACSONE) 5 years ago
committed by Luis Torres
parent
commit
cb381a52d1
  1. 32
      partner_firstname/__manifest__.py
  2. 4
      partner_firstname/hooks.py
  3. 9
      partner_firstname/migrations/12.0.1.0.0/pre-ir_config_param.py
  4. 56
      partner_firstname/models/base_config_settings.py
  5. 83
      partner_firstname/models/res_partner.py
  6. 33
      partner_firstname/models/res_users.py
  7. 25
      partner_firstname/tests/base.py
  8. 28
      partner_firstname/tests/test_copy.py
  9. 25
      partner_firstname/tests/test_create.py
  10. 28
      partner_firstname/tests/test_defaults.py
  11. 1
      partner_firstname/tests/test_delete.py
  12. 24
      partner_firstname/tests/test_empty.py
  13. 8
      partner_firstname/tests/test_name.py
  14. 28
      partner_firstname/tests/test_order.py
  15. 1
      partner_firstname/tests/test_user_onchange.py

32
partner_firstname/__manifest__.py

@ -4,26 +4,26 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
'name': 'Partner first name and last name',
'summary': "Split first name and last name for non company partners",
'version': '12.0.1.0.0',
'author': "Camptocamp, "
"name": "Partner first name and last name",
"summary": "Split first name and last name for non company partners",
"version": "13.0.1.0.0",
"author": "Camptocamp, "
"Grupo ESOC Ingeniería de Servicios, "
"Tecnativa, "
"LasLabs, "
"ACSONE SA/NV, "
"Odoo Community Association (OCA)",
'license': "AGPL-3",
'maintainer': 'Camptocamp, Acsone',
'category': 'Extra Tools',
'website': 'https://odoo-community.org/',
'depends': ['base_setup'],
'post_init_hook': 'post_init_hook',
'data': [
'views/base_config_view.xml',
'views/res_partner.xml',
'views/res_user.xml',
"license": "AGPL-3",
"maintainer": "Camptocamp, Acsone",
"category": "Extra Tools",
"website": "https://odoo-community.org/",
"depends": ["base_setup"],
"post_init_hook": "post_init_hook",
"data": [
"views/base_config_view.xml",
"views/res_partner.xml",
"views/res_user.xml",
],
'auto_install': False,
'installable': True,
"auto_install": False,
"installable": True,
}

4
partner_firstname/hooks.py

@ -1,10 +1,10 @@
# Copyright 2017 LasLabs Inc.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, SUPERUSER_ID
from odoo import SUPERUSER_ID, api
def post_init_hook(cr, _):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
env['res.partner']._install_partner_firstname()
env["res.partner"]._install_partner_firstname()

9
partner_firstname/migrations/12.0.1.0.0/pre-ir_config_param.py

@ -3,11 +3,12 @@ def store_ir_config_param(cr):
names was last_first. In order to retain this behaviour we
store the config parameter if it is not present.
"""
cr.execute("SELECT 1 FROM ir_config_parameter "
"WHERE key = 'partner_names_order'")
cr.execute("SELECT 1 FROM ir_config_parameter " "WHERE key = 'partner_names_order'")
if not cr.fetchone():
cr.execute("INSERT INTO ir_config_parameter (key, value) VALUES "
"('partner_names_order', 'last_first')")
cr.execute(
"INSERT INTO ir_config_parameter (key, value) VALUES "
"('partner_names_order', 'last_first')"
)
def migrate(cr, version):

56
partner_firstname/models/base_config_settings.py

@ -2,12 +2,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import api, fields, models
_logger = logging.getLogger(__name__)
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
_inherit = "res.config.settings"
partner_names_order = fields.Selection(
string="Partner names order",
@ -15,36 +17,41 @@ class ResConfigSettings(models.TransientModel):
help="Order to compose partner fullname",
required=True,
)
partner_names_order_changed = fields.Boolean(
compute="_compute_names_order_changed",
)
partner_names_order_changed = fields.Boolean(compute="_compute_names_order_changed")
def _partner_names_order_selection(self):
return [
('last_first', 'Lastname Firstname'),
('last_first_comma', 'Lastname, Firstname'),
('first_last', 'Firstname Lastname'),
("last_first", "Lastname Firstname"),
("last_first_comma", "Lastname, Firstname"),
("first_last", "Firstname Lastname"),
]
@api.multi
def _partner_names_order_default(self):
return self.env['res.partner']._names_order_default()
return self.env["res.partner"]._names_order_default()
@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
partner_names_order = self.env['ir.config_parameter'].sudo().get_param(
'partner_names_order',
default=self._partner_names_order_default()
partner_names_order = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"partner_names_order", default=self._partner_names_order_default()
)
)
res.update(partner_names_order=partner_names_order)
return res
@api.multi
@api.depends('partner_names_order')
@api.depends("partner_names_order")
def _compute_names_order_changed(self):
current = self.env['ir.config_parameter'].sudo().get_param(
'partner_names_order', default=self._partner_names_order_default()
current = (
self.env["ir.config_parameter"]
.sudo()
.get_param(
"partner_names_order", default=self._partner_names_order_default()
)
)
for record in self:
record.partner_names_order_changed = bool(
@ -52,28 +59,31 @@ class ResConfigSettings(models.TransientModel):
)
@api.multi
@api.onchange('partner_names_order')
@api.onchange("partner_names_order")
def _onchange_partner_names_order(self):
self._compute_names_order_changed()
@api.multi
def set_values(self):
super(ResConfigSettings, self).set_values()
self.env['ir.config_parameter'].sudo().set_param(
'partner_names_order', self.partner_names_order
self.env["ir.config_parameter"].sudo().set_param(
"partner_names_order", self.partner_names_order
)
@api.multi
def _partners_for_recalculating(self):
return self.env['res.partner'].search([
('is_company', '=', False),
('firstname', '!=', False), ('lastname', '!=', False),
])
return self.env["res.partner"].search(
[
("is_company", "=", False),
("firstname", "!=", False),
("lastname", "!=", False),
]
)
@api.multi
def action_recalculate_partners_name(self):
self.env['ir.config_parameter'].sudo().set_param(
'partner_names_order', self.partner_names_order
self.env["ir.config_parameter"].sudo().set_param(
"partner_names_order", self.partner_names_order
)
partners = self._partners_for_recalculating()
_logger.info("Recalculating names for %d partners.", len(partners))

83
partner_firstname/models/res_partner.py

@ -3,7 +3,9 @@
# Copyright 2015 Grupo ESOC (<http://www.grupoesoc.es>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging
from odoo import api, fields, models
from .. import exceptions
_logger = logging.getLogger(__name__)
@ -11,21 +13,17 @@ _logger = logging.getLogger(__name__)
class ResPartner(models.Model):
"""Adds last name and first name; name becomes a stored function field."""
_inherit = 'res.partner'
firstname = fields.Char(
"First name",
index=True,
)
lastname = fields.Char(
"Last name",
index=True,
)
_inherit = "res.partner"
firstname = fields.Char("First name", index=True)
lastname = fields.Char("Last name", index=True)
name = fields.Char(
compute="_compute_name",
inverse="_inverse_name_after_cleaning_whitespace",
required=False,
store=True)
store=True,
)
@api.model
def create(self, vals):
@ -37,8 +35,8 @@ class ResPartner(models.Model):
# Calculate the splitted fields
inverted = self._get_inverse_name(
self._get_whitespace_cleaned_name(name),
vals.get("is_company",
self.default_get(["is_company"])["is_company"]))
vals.get("is_company", self.default_get(["is_company"])["is_company"]),
)
for key, value in inverted.items():
if not vals.get(key) or context.get("copy"):
vals[key] = value
@ -68,7 +66,8 @@ class ResPartner(models.Model):
inverted = self._get_inverse_name(
self._get_whitespace_cleaned_name(result.get("name", "")),
result.get("is_company", False))
result.get("is_company", False),
)
for field in list(inverted.keys()):
if field in fields_list:
@ -78,15 +77,18 @@ class ResPartner(models.Model):
@api.model
def _names_order_default(self):
return 'first_last'
return "first_last"
@api.model
def _get_names_order(self):
"""Get names order configuration from system parameters.
You can override this method to read configuration from language,
country, company or other"""
return self.env['ir.config_parameter'].sudo().get_param(
'partner_names_order', self._names_order_default())
return (
self.env["ir.config_parameter"]
.sudo()
.get_param("partner_names_order", self._names_order_default())
)
@api.model
def _get_computed_name(self, lastname, firstname):
@ -94,21 +96,19 @@ class ResPartner(models.Model):
You can override this method to change the order of lastname and
firstname the computed name"""
order = self._get_names_order()
if order == 'last_first_comma':
return ", ".join((p for p in (lastname, firstname) if p))
elif order == 'first_last':
return " ".join((p for p in (firstname, lastname) if p))
if order == "last_first_comma":
return ", ".join(p for p in (lastname, firstname) if p)
elif order == "first_last":
return " ".join(p for p in (firstname, lastname) if p)
else:
return " ".join((p for p in (lastname, firstname) if p))
return " ".join(p for p in (lastname, firstname) if p)
@api.multi
@api.depends("firstname", "lastname")
def _compute_name(self):
"""Write the 'name' field according to splitted data."""
for record in self:
record.name = record._get_computed_name(
record.lastname, record.firstname,
)
record.name = record._get_computed_name(record.lastname, record.firstname)
@api.multi
def _inverse_name_after_cleaning_whitespace(self):
@ -144,7 +144,7 @@ class ResPartner(models.Model):
# conversion that Python does for us.
# In that case we need to manually decode the string to get a
# proper unicode string.
name = ' '.join(name.decode('utf-8').split()) if name else name
name = " ".join(name.decode("utf-8").split()) if name else name
if comma:
name = name.replace(" ,", ",")
@ -173,10 +173,11 @@ class ResPartner(models.Model):
order = self._get_names_order()
# Remove redundant spaces
name = self._get_whitespace_cleaned_name(
name, comma=(order == 'last_first_comma'))
parts = name.split("," if order == 'last_first_comma' else " ", 1)
name, comma=(order == "last_first_comma")
)
parts = name.split("," if order == "last_first_comma" else " ", 1)
if len(parts) > 1:
if order == 'first_last':
if order == "first_last":
parts = [" ".join(parts[1:]), parts[0]]
else:
parts = [parts[0], " ".join(parts[1:])]
@ -190,18 +191,20 @@ class ResPartner(models.Model):
"""Try to revert the effect of :meth:`._compute_name`."""
for record in self:
parts = record._get_inverse_name(record.name, record.is_company)
record.lastname = parts['lastname']
record.firstname = parts['firstname']
record.lastname = parts["lastname"]
record.firstname = parts["firstname"]
@api.multi
@api.constrains("firstname", "lastname")
def _check_name(self):
"""Ensure at least one name is set."""
for record in self:
if all((
record.type == 'contact' or record.is_company,
not (record.firstname or record.lastname)
)):
if all(
(
record.type == "contact" or record.is_company,
not (record.firstname or record.lastname),
)
):
raise exceptions.EmptyNamesError(record)
@api.onchange("firstname", "lastname")
@ -220,8 +223,7 @@ class ResPartner(models.Model):
"""Ensure :attr:`~.name` is inverted in the UI."""
if self.env.context.get("skip_onchange"):
# Do not skip next onchange
self.env.context = (
self.with_context(skip_onchange=False).env.context)
self.env.context = self.with_context(skip_onchange=False).env.context
else:
self._inverse_name_after_cleaning_whitespace()
@ -234,8 +236,7 @@ class ResPartner(models.Model):
correctly into the database. This can be called later too if needed.
"""
# Find records with empty firstname and lastname
records = self.search([("firstname", "=", False),
("lastname", "=", False)])
records = self.search([("firstname", "=", False), ("lastname", "=", False)])
# Force calculations there
records._inverse_name()
@ -243,8 +244,4 @@ class ResPartner(models.Model):
# Disabling SQL constraint givint a more explicit error using a Python
# contstraint
_sql_constraints = [(
'check_name',
"CHECK( 1=1 )",
'Contacts require a name.'
)]
_sql_constraints = [("check_name", "CHECK( 1=1 )", "Contacts require a name.")]

33
partner_firstname/models/res_users.py

@ -2,21 +2,22 @@
# Copyright 2014 Agile Business Group (<http://www.agilebg.com>)
# Copyright 2015 Grupo ESOC (<http://www.grupoesoc.es>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, models, _
from odoo import _, api, models
class ResUser(models.Model):
_inherit = 'res.users'
_inherit = "res.users"
@api.model
def default_get(self, fields_list):
"""Invert name when getting default values."""
result = super(ResUser, self).default_get(fields_list)
partner_model = self.env['res.partner']
partner_model = self.env["res.partner"]
inverted = partner_model._get_inverse_name(
partner_model._get_whitespace_cleaned_name(result.get("name", "")),
result.get("is_company", False))
result.get("is_company", False),
)
for field in list(inverted.keys()):
if field in fields_list:
@ -28,22 +29,22 @@ class ResUser(models.Model):
def _compute_name(self):
"""Write the 'name' field according to splitted data."""
for rec in self:
rec.name = rec.partner_id._get_computed_name(
rec.lastname, rec.firstname)
rec.name = rec.partner_id._get_computed_name(rec.lastname, rec.firstname)
@api.multi
def copy(self, default=None):
self.ensure_one()
default = dict(default or {})
if (('name' not in default) and
('partner_id' not in default)):
default['name'] = _("%s (copy)") % self.name
if 'login' not in default:
default['login'] = _("%s (copy)") % self.login
if (('firstname' not in default) and
('lastname' not in default) and
('name' in default)):
default.update(self.env['res.partner']._get_inverse_name(
default['name'], False)
if ("name" not in default) and ("partner_id" not in default):
default["name"] = _("%s (copy)") % self.name
if "login" not in default:
default["login"] = _("%s (copy)") % self.login
if (
("firstname" not in default)
and ("lastname" not in default)
and ("name" in default)
):
default.update(
self.env["res.partner"]._get_inverse_name(default["name"], False)
)
return super(ResUser, self).copy(default)

25
partner_firstname/tests/base.py

@ -1,17 +1,18 @@
# Copyright 2014 Nemry Jonathan (Acsone SA/NV) (http://www.acsone.eu)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from .. import exceptions as ex
class MailInstalled():
class MailInstalled:
def mail_installed(self):
"""Check if ``mail`` module is installed.``"""
return (self.env["ir.module.module"]
.search([("name", "=", "mail")])
.state == "installed")
return (
self.env["ir.module.module"].search([("name", "=", "mail")]).state
== "installed"
)
class BaseCase(TransactionCase, MailInstalled):
@ -22,15 +23,15 @@ class BaseCase(TransactionCase, MailInstalled):
self.create_original()
def create_original(self):
self.original = self.env["res.partner"].create({
"firstname": self.firstname,
"lastname": self.lastname})
self.original = self.env["res.partner"].create(
{"firstname": self.firstname, "lastname": self.lastname}
)
def expect(self, lastname, firstname, name=None):
"""Define what is expected in each field when ending."""
self.lastname = lastname
self.firstname = firstname
self.name = name or "%s %s" % (firstname, lastname)
self.name = name or "{} {}".format(firstname, lastname)
def tearDown(self):
if self.check_fields:
@ -41,15 +42,15 @@ class BaseCase(TransactionCase, MailInstalled):
self.assertEqual(
getattr(self.changed, field),
getattr(self, field),
"Test failed with wrong %s" % field)
"Test failed with wrong %s" % field,
)
super(BaseCase, self).tearDown()
def test_copy(self):
"""Copy the partner and compare the result."""
self.expect("%s (copy)" % self.lastname, self.firstname)
self.changed = (self.original.with_context(copy=True, lang="en_US")
.copy())
self.changed = self.original.with_context(copy=True, lang="en_US").copy()
def test_one_name(self):
"""Test what happens when only one name is given."""

28
partner_firstname/tests/test_copy.py

@ -1,6 +1,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
"""Test copy function for models."""
from odoo.tests.common import TransactionCase
from .base import MailInstalled
@ -12,12 +13,14 @@ class UserCase(TransactionCase, MailInstalled):
self.create_original()
def create_original(self):
self.original = self.env["res.users"].create({
self.original = self.env["res.users"].create(
{
"firstname": u"Firstname",
"lastname": u"Lastname",
"name": u"Firstname Lastname",
"login": u"firstname.lastname"
})
"login": u"firstname.lastname",
}
)
def tearDown(self):
super(UserCase, self).tearDown()
@ -29,24 +32,23 @@ class UserCase(TransactionCase, MailInstalled):
def test_copy_name(self):
"""Copy original with default name set - firstname lastname not set."""
copy = self.original.copy({
"name": u"Firstname2 Lastname2"
})
copy = self.original.copy({"name": u"Firstname2 Lastname2"})
self.compare(copy)
def test_copy_firstname_lastname(self):
"""Copy original with default firstname and lastname set"""
copy = self.original.copy({
"firstname": u"Firstname2",
"lastname": u"Lastname2"
})
copy = self.original.copy(
{"firstname": u"Firstname2", "lastname": u"Lastname2"}
)
self.compare(copy)
def test_copy_firstname_lastname_name(self):
"""Copy original with default firstname, lastname and name set"""
copy = self.original.copy({
copy = self.original.copy(
{
"firstname": u"Firstname2",
"lastname": u"Lastname2",
"name": u"Firstname2 Lastname2"
})
"name": u"Firstname2 Lastname2",
}
)
self.compare(copy)

25
partner_firstname/tests/test_create.py

@ -4,35 +4,32 @@
"""Test default values for models."""
from odoo.tests.common import TransactionCase
from .base import MailInstalled
class PersonCase(TransactionCase):
"""Test ``res.partner`` when it is a person."""
context = {"default_is_company": False}
model = "res.partner"
def setUp(self):
super(PersonCase, self).setUp()
self.good_values = {
"firstname": "Núñez",
"lastname": "Fernán",
}
self.good_values["name"] = "%s %s" % (self.good_values["firstname"],
self.good_values["lastname"])
self.good_values = {"firstname": "Núñez", "lastname": "Fernán"}
self.good_values["name"] = "{} {}".format(
self.good_values["firstname"], self.good_values["lastname"]
)
if "default_is_company" in self.context:
self.good_values["is_company"] = self.context["default_is_company"]
self.values = self.good_values.copy()
def tearDown(self):
self.record = (self.env[self.model]
.with_context(self.context)
.create(self.values))
self.record = (
self.env[self.model].with_context(self.context).create(self.values)
)
for key, value in self.good_values.items():
self.assertEqual(
self.record[key],
value,
"Checking key %s" % key)
self.assertEqual(self.record[key], value, "Checking key %s" % key)
super(PersonCase, self).tearDown()
@ -57,6 +54,7 @@ class PersonCase(TransactionCase):
class CompanyCase(PersonCase):
"""Test ``res.partner`` when it is a company."""
context = {"default_is_company": True}
def setUp(self):
@ -67,6 +65,7 @@ class CompanyCase(PersonCase):
class UserCase(PersonCase, MailInstalled):
"""Test ``res.users``."""
model = "res.users"
context = {"default_login": "user@example.com"}

28
partner_firstname/tests/test_defaults.py

@ -4,44 +4,43 @@
"""Test default values for models."""
from odoo.tests.common import TransactionCase
from .base import MailInstalled
class PersonCase(TransactionCase):
"""Test ``res.partner`` when it is a person."""
context = {"default_is_company": False}
model = "res.partner"
def setUp(self):
super(PersonCase, self).setUp()
self.values = {
"firstname": "Núñez",
"lastname": "Fernán",
}
self.values["name"] = "%s %s" % (self.values["firstname"],
self.values["lastname"])
self.values = {"firstname": "Núñez", "lastname": "Fernán"}
self.values["name"] = "{} {}".format(
self.values["firstname"], self.values["lastname"]
)
if "default_is_company" in self.context:
self.values["is_company"] = self.context["default_is_company"]
def tearDown(self):
for key, value in self.values.items():
self.assertEqual(
self.defaults.get(key),
value,
"Checking key %s" % key)
self.assertEqual(self.defaults.get(key), value, "Checking key %s" % key)
return super(PersonCase, self).tearDown()
def test_default_get(self):
"""Getting default values for fields includes new fields."""
self.defaults = (self.env[self.model]
.with_context(self.context,
default_name=self.values["name"])
.default_get(list(self.values.keys())))
self.defaults = (
self.env[self.model]
.with_context(self.context, default_name=self.values["name"])
.default_get(list(self.values.keys()))
)
class CompanyCase(PersonCase):
"""Test ``res.partner`` when it is a company."""
context = {"default_is_company": True}
def tearDown(self):
@ -51,6 +50,7 @@ class CompanyCase(PersonCase):
class UserCase(PersonCase, MailInstalled):
"""Test ``res.users``."""
model = "res.users"
context = {"default_login": "user@example.com"}

1
partner_firstname/tests/test_delete.py

@ -2,6 +2,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase
from .base import MailInstalled

24
partner_firstname/tests/test_empty.py

@ -6,12 +6,14 @@
To have more accurate results, remove the ``mail`` module before testing.
"""
from odoo.tests.common import TransactionCase
from .base import MailInstalled
from .. import exceptions as ex
from .base import MailInstalled
class CompanyCase(TransactionCase):
"""Test ``res.partner`` when it is a company."""
model = "res.partner"
context = {"default_is_company": True}
@ -35,11 +37,13 @@ class CompanyCase(TransactionCase):
class PersonCase(CompanyCase):
"""Test ``res.partner`` when it is a person."""
context = {"default_is_company": False, "default_type": 'contact'}
context = {"default_is_company": False, "default_type": "contact"}
class UserCase(CompanyCase, MailInstalled):
"""Test ``res.users``."""
model = "res.users"
context = {"default_login": "user@example.com"}
@ -58,16 +62,12 @@ class AddressCase(TransactionCase):
def test_new_empty_invoice_address(self):
"""Create an invoice patner without name."""
self.original = self.env["res.partner"].create({
"is_company": False,
"type": 'invoice',
"lastname": "",
"firstname": ""})
self.original = self.env["res.partner"].create(
{"is_company": False, "type": "invoice", "lastname": "", "firstname": ""}
)
def test_new_empty_shipping_address(self):
"""Create an shipping patner without name."""
self.original = self.env["res.partner"].create({
"is_company": False,
"type": 'delivery',
"lastname": "",
"firstname": ""})
self.original = self.env["res.partner"].create(
{"is_company": False, "type": "delivery", "lastname": "", "firstname": ""}
)

8
partner_firstname/tests/test_name.py

@ -70,16 +70,16 @@ class PartnerCompanyCase(BaseCase):
class UserCase(PartnerContactCase):
def create_original(self):
name = "%s %s" % (self.firstname, self.lastname)
name = "{} {}".format(self.firstname, self.lastname)
# Cannot create users if ``mail`` is installed
if self.mail_installed():
self.original = self.env.ref("base.user_demo")
self.original.name = name
else:
self.original = self.env["res.users"].create({
"name": name,
"login": "firstnametest@example.com"})
self.original = self.env["res.users"].create(
{"name": name, "login": "firstnametest@example.com"}
)
def test_copy(self):
"""Copy the partner and compare the result."""

28
partner_firstname/tests/test_order.py

@ -6,34 +6,36 @@ from odoo.tests.common import TransactionCase
class PartnerNamesOrder(TransactionCase):
def order_set(self, order):
return self.env['ir.config_parameter'].sudo().set_param(
'partner_names_order', order)
return (
self.env["ir.config_parameter"]
.sudo()
.set_param("partner_names_order", order)
)
def test_get_computed_name(self):
lastname = "García Lorca"
firstname = "Federico"
cases = (
('last_first', "García Lorca Federico"),
('last_first_comma', "García Lorca, Federico"),
('first_last', "Federico García Lorca"),
("last_first", "García Lorca Federico"),
("last_first_comma", "García Lorca, Federico"),
("first_last", "Federico García Lorca"),
)
for order, name in cases:
self.order_set(order)
result = self.env['res.partner']._get_computed_name(
lastname, firstname)
result = self.env["res.partner"]._get_computed_name(lastname, firstname)
self.assertEqual(result, name)
def test_get_inverse_name(self):
lastname = "Flanker"
firstname = "Petër"
cases = (
('last_first', "Flanker Petër"),
('last_first_comma', "Flanker, Petër"),
('first_last', "Petër Flanker"),
("last_first", "Flanker Petër"),
("last_first_comma", "Flanker, Petër"),
("first_last", "Petër Flanker"),
)
for order, name in cases:
self.order_set(order)
result = self.env['res.partner']._get_inverse_name(name)
self.assertEqual(result['lastname'], lastname)
self.assertEqual(result['firstname'], firstname)
result = self.env["res.partner"]._get_inverse_name(name)
self.assertEqual(result["lastname"], lastname)
self.assertEqual(result["firstname"], firstname)

1
partner_firstname/tests/test_user_onchange.py

@ -5,7 +5,6 @@ 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ë"

Loading…
Cancel
Save