From 01a92d1f54368aec238f646a77b30b09e1b19b64 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Mon, 9 Oct 2017 13:09:47 +0200 Subject: [PATCH] [MIG] partner_firstname --- partner_firstname/README.rst | 4 +- partner_firstname/__manifest__.py | 2 +- partner_firstname/exceptions.py | 2 +- partner_firstname/i18n/es.po | 4 +- partner_firstname/i18n/fr.po | 2 +- partner_firstname/i18n/nl_NL.po | 4 +- .../models/base_config_settings.py | 34 ++++++++------ partner_firstname/models/res_partner.py | 18 +++---- partner_firstname/models/res_users.py | 2 +- partner_firstname/tests/base.py | 8 ++-- partner_firstname/tests/test_create.py | 14 +++--- partner_firstname/tests/test_defaults.py | 8 ++-- partner_firstname/tests/test_delete.py | 2 +- partner_firstname/tests/test_name.py | 10 ++-- partner_firstname/tests/test_onchange.py | 16 +++---- partner_firstname/tests/test_order.py | 24 +++++----- partner_firstname/tests/test_user_onchange.py | 10 ++-- partner_firstname/views/base_config_view.xml | 47 ++++++++++--------- 18 files changed, 109 insertions(+), 102 deletions(-) diff --git a/partner_firstname/README.rst b/partner_firstname/README.rst index 2b045f04f..7f3fd00a0 100644 --- a/partner_firstname/README.rst +++ b/partner_firstname/README.rst @@ -13,7 +13,7 @@ Configuration ============= You can configure some common name patterns for the inverse function -in Settings > Configuration > General settings: +in Settings > General settings: * Lastname Firstname: For example 'Anderson Robert' * Lastname, Firstname: For example 'Anderson, Robert' @@ -47,7 +47,7 @@ supply the *last name* and *first name* (just once per contact). .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/134/10.0 + :target: https://runbot.odoo-community.org/runbot/134/11.0 For further information, please visit: diff --git a/partner_firstname/__manifest__.py b/partner_firstname/__manifest__.py index 34561ed56..014d46917 100644 --- a/partner_firstname/__manifest__.py +++ b/partner_firstname/__manifest__.py @@ -7,7 +7,7 @@ { 'name': 'Partner first name and last name', 'summary': "Split first name and last name for non company partners", - 'version': '10.0.2.1.0', + 'version': '11.0.1.0.0', 'author': "Camptocamp, " "Grupo ESOC Ingeniería de Servicios, " "Tecnativa, " diff --git a/partner_firstname/exceptions.py b/partner_firstname/exceptions.py index d2fdea566..4714b7001 100644 --- a/partner_firstname/exceptions.py +++ b/partner_firstname/exceptions.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # © 2014-2015 Grupo ESOC () # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp import _, exceptions +from odoo import _, exceptions class EmptyNamesError(exceptions.ValidationError): diff --git a/partner_firstname/i18n/es.po b/partner_firstname/i18n/es.po index d51befbbc..2201ca247 100644 --- a/partner_firstname/i18n/es.po +++ b/partner_firstname/i18n/es.po @@ -86,5 +86,5 @@ msgstr "Usuarios" #. module: partner_firstname #: model:ir.model,name:partner_firstname.model_base_config_settings -msgid "base.config.settings" -msgstr "base.config.settings" +msgid "res.config.settings" +msgstr "res.config.settings" diff --git a/partner_firstname/i18n/fr.po b/partner_firstname/i18n/fr.po index 4017cd747..5c92f1ab2 100644 --- a/partner_firstname/i18n/fr.po +++ b/partner_firstname/i18n/fr.po @@ -90,5 +90,5 @@ msgstr "Utilisateurs" #. module: partner_firstname #: model:ir.model,name:partner_firstname.model_base_config_settings -msgid "base.config.settings" +msgid "res.config.settings" msgstr "" diff --git a/partner_firstname/i18n/nl_NL.po b/partner_firstname/i18n/nl_NL.po index 38b0123b4..59c12c5f9 100644 --- a/partner_firstname/i18n/nl_NL.po +++ b/partner_firstname/i18n/nl_NL.po @@ -88,5 +88,5 @@ msgstr "Gebruikers" #. module: partner_firstname #: model:ir.model,name:partner_firstname.model_base_config_settings -msgid "base.config.settings" -msgstr "base.config.settings" +msgid "res.config.settings" +msgstr "res.config.settings" diff --git a/partner_firstname/models/base_config_settings.py b/partner_firstname/models/base_config_settings.py index 35d2b52fe..7d7a98a43 100644 --- a/partner_firstname/models/base_config_settings.py +++ b/partner_firstname/models/base_config_settings.py @@ -3,12 +3,12 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging -from openerp import api, fields, models +from odoo import api, fields, models _logger = logging.getLogger(__name__) -class BaseConfigSettings(models.TransientModel): - _inherit = 'base.config.settings' +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' partner_names_order = fields.Selection( string="Partner names order", @@ -32,18 +32,20 @@ class BaseConfigSettings(models.TransientModel): return self.env['res.partner']._names_order_default() @api.model - def get_default_partner_names_order(self, fields): - return { - 'partner_names_order': self.env['ir.config_parameter'].get_param( - 'partner_names_order', self._partner_names_order_default(), - ), - } + 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() + ) + res.update(partner_names_order=partner_names_order) + return res @api.multi @api.depends('partner_names_order') def _compute_names_order_changed(self): - current = self.env['ir.config_parameter'].get_param( - 'partner_names_order', 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( @@ -53,12 +55,14 @@ class BaseConfigSettings(models.TransientModel): @api.multi @api.onchange('partner_names_order') def _onchange_partner_names_order(self): - self.partner_names_order_changed = self._compute_names_order_changed() + self._compute_names_order_changed() @api.multi - def set_partner_names_order(self): - self.env['ir.config_parameter'].set_param( - 'partner_names_order', self.partner_names_order) + def set_values(self): + super(ResConfigSettings, self).set_values() + self.env['ir.config_parameter'].sudo().set_param( + 'partner_names_order', self.partner_names_order + ) @api.multi def _partners_for_recalculating(self): diff --git a/partner_firstname/models/res_partner.py b/partner_firstname/models/res_partner.py index b9b6bfe7d..2f146fd71 100644 --- a/partner_firstname/models/res_partner.py +++ b/partner_firstname/models/res_partner.py @@ -41,7 +41,7 @@ class ResPartner(models.Model): vals.get("is_company", self.default_get(["is_company"])["is_company"])) - for key, value in inverted.iteritems(): + for key, value in inverted.items(): if not vals.get(key) or context.get("copy"): vals[key] = value @@ -72,7 +72,7 @@ class ResPartner(models.Model): self._get_whitespace_cleaned_name(result.get("name", "")), result.get("is_company", False)) - for field in inverted.keys(): + for field in list(inverted.keys()): if field in fields_list: result[field] = inverted.get(field) @@ -97,11 +97,11 @@ class ResPartner(models.Model): firstname the computed name""" order = self._get_names_order() if order == 'last_first_comma': - return u", ".join((p for p in (lastname, firstname) if p)) + return ", ".join((p for p in (lastname, firstname) if p)) elif order == 'first_last': - return u" ".join((p for p in (firstname, lastname) if p)) + return " ".join((p for p in (firstname, lastname) if p)) else: - return u" ".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") @@ -138,7 +138,7 @@ class ResPartner(models.Model): Removes leading, trailing and duplicated whitespace. """ try: - name = u" ".join(name.split()) if name else name + name = " ".join(name.split()) if name else name except UnicodeDecodeError: # with users coming from LDAP, name can be a str encoded as utf-8 # this happens with ActiveDirectory for instance, and in that case @@ -146,7 +146,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 = u' '.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(" ,", ",") @@ -179,9 +179,9 @@ class ResPartner(models.Model): parts = name.split("," if order == 'last_first_comma' else " ", 1) if len(parts) > 1: if order == 'first_last': - parts = [u" ".join(parts[1:]), parts[0]] + parts = [" ".join(parts[1:]), parts[0]] else: - parts = [parts[0], u" ".join(parts[1:])] + parts = [parts[0], " ".join(parts[1:])] else: while len(parts) < 2: parts.append(False) diff --git a/partner_firstname/models/res_users.py b/partner_firstname/models/res_users.py index cea1aa332..85143b4c7 100644 --- a/partner_firstname/models/res_users.py +++ b/partner_firstname/models/res_users.py @@ -23,7 +23,7 @@ class ResUser(models.Model): partner_model._get_whitespace_cleaned_name(result.get("name", "")), result.get("is_company", False)) - for field in inverted.keys(): + for field in list(inverted.keys()): if field in fields_list: result[field] = inverted.get(field) diff --git a/partner_firstname/tests/base.py b/partner_firstname/tests/base.py index c6236c866..5d619e67c 100644 --- a/partner_firstname/tests/base.py +++ b/partner_firstname/tests/base.py @@ -18,7 +18,7 @@ class BaseCase(TransactionCase, MailInstalled): def setUp(self): super(BaseCase, self).setUp() self.check_fields = True - self.expect(u"Núñez", u"Fernán") + self.expect("Núñez", "Fernán") self.create_original() def create_original(self): @@ -30,7 +30,7 @@ class BaseCase(TransactionCase, MailInstalled): """Define what is expected in each field when ending.""" self.lastname = lastname self.firstname = firstname - self.name = name or u"%s %s" % (lastname, firstname) + self.name = name or "%s %s" % (lastname, firstname) def tearDown(self): if self.check_fields: @@ -47,13 +47,13 @@ class BaseCase(TransactionCase, MailInstalled): def test_copy(self): """Copy the partner and compare the result.""" - self.expect(self.lastname, u"%s (copy)" % self.firstname) + self.expect(self.lastname, "%s (copy)" % self.firstname) 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.""" - name = u"Mönty" + name = "Mönty" self.expect(name, False, name) self.original.name = name diff --git a/partner_firstname/tests/test_create.py b/partner_firstname/tests/test_create.py index 6d80abdad..99802dbe1 100644 --- a/partner_firstname/tests/test_create.py +++ b/partner_firstname/tests/test_create.py @@ -16,8 +16,8 @@ class PersonCase(TransactionCase): def setUp(self): super(PersonCase, self).setUp() self.good_values = { - "firstname": u"Núñez", - "lastname": u"Fernán", + "firstname": "Núñez", + "lastname": "Fernán", } self.good_values["name"] = "%s %s" % (self.good_values["lastname"], self.good_values["firstname"]) @@ -29,7 +29,7 @@ class PersonCase(TransactionCase): self.record = (self.env[self.model] .with_context(self.context) .create(self.values)) - for key, value in self.good_values.iteritems(): + for key, value in self.good_values.items(): self.assertEqual( self.record[key], value, @@ -43,17 +43,17 @@ class PersonCase(TransactionCase): def test_wrong_name_value(self): """Wrong name value is ignored, name is calculated.""" - self.values["name"] = u"BÄD" + self.values["name"] = "BÄD" def test_wrong_name_context(self): """Wrong name context is ignored, name is calculated.""" del self.values["name"] - self.context["default_name"] = u"BÄD" + self.context["default_name"] = "BÄD" def test_wrong_name_value_and_context(self): """Wrong name value and context is ignored, name is calculated.""" - self.values["name"] = u"BÄD1" - self.context["default_name"] = u"BÄD2" + self.values["name"] = "BÄD1" + self.context["default_name"] = "BÄD2" class CompanyCase(PersonCase): diff --git a/partner_firstname/tests/test_defaults.py b/partner_firstname/tests/test_defaults.py index 304e9583d..6eac96a7e 100644 --- a/partner_firstname/tests/test_defaults.py +++ b/partner_firstname/tests/test_defaults.py @@ -16,8 +16,8 @@ class PersonCase(TransactionCase): def setUp(self): super(PersonCase, self).setUp() self.values = { - "firstname": u"Núñez", - "lastname": u"Fernán", + "firstname": "Núñez", + "lastname": "Fernán", } self.values["name"] = "%s %s" % (self.values["lastname"], self.values["firstname"]) @@ -25,7 +25,7 @@ class PersonCase(TransactionCase): self.values["is_company"] = self.context["default_is_company"] def tearDown(self): - for key, value in self.values.iteritems(): + for key, value in self.values.items(): self.assertEqual( self.defaults.get(key), value, @@ -38,7 +38,7 @@ class PersonCase(TransactionCase): self.defaults = (self.env[self.model] .with_context(self.context, default_name=self.values["name"]) - .default_get(self.values.keys())) + .default_get(list(self.values.keys()))) class CompanyCase(PersonCase): diff --git a/partner_firstname/tests/test_delete.py b/partner_firstname/tests/test_delete.py index 070a92a6a..40979d671 100644 --- a/partner_firstname/tests/test_delete.py +++ b/partner_firstname/tests/test_delete.py @@ -18,7 +18,7 @@ class CompanyCase(TransactionCase): See https://github.com/OCA/partner-contact/issues/154. """ - data = {"name": u"Söme name"} + data = {"name": "Söme name"} record = self.env[self.model].with_context(**self.context).create(data) record.unlink() record.recompute() diff --git a/partner_firstname/tests/test_name.py b/partner_firstname/tests/test_name.py index f471ad16e..0c699bbd5 100644 --- a/partner_firstname/tests/test_name.py +++ b/partner_firstname/tests/test_name.py @@ -36,17 +36,17 @@ from .base import BaseCase class PartnerContactCase(BaseCase): def test_update_lastname(self): """Change lastname.""" - self.expect(u"newlästname", self.firstname) + self.expect("newlästname", self.firstname) self.original.name = self.name def test_update_firstname(self): """Change firstname.""" - self.expect(self.lastname, u"newfïrstname") + self.expect(self.lastname, "newfïrstname") self.original.name = self.name def test_whitespace_cleanup(self): """Check that whitespace in name gets cleared.""" - self.expect(u"newlästname", u"newfïrstname") + self.expect("newlästname", "newfïrstname") self.original.name = " newlästname newfïrstname " # Need this to refresh the ``name`` field @@ -65,14 +65,14 @@ class PartnerCompanyCase(BaseCase): def test_company_inverse(self): """Test the inverse method in a company record.""" - name = u"Thïs is a Companŷ" + name = "Thïs is a Companŷ" self.expect(name, False, name) self.original.name = name class UserCase(PartnerContactCase): def create_original(self): - name = u"%s %s" % (self.lastname, self.firstname) + name = "%s %s" % (self.lastname, self.firstname) # Cannot create users if ``mail`` is installed if self.mail_installed(): diff --git a/partner_firstname/tests/test_onchange.py b/partner_firstname/tests/test_onchange.py index 573f30522..8201eaf70 100644 --- a/partner_firstname/tests/test_onchange.py +++ b/partner_firstname/tests/test_onchange.py @@ -15,7 +15,7 @@ class PartnerCompanyCase(OnChangeCase): def test_create_from_form(self): """A user creates a company from the form.""" - name = u"Sôme company" + name = "Sôme company" with self.env.do_in_onchange(): # User presses ``new`` partner = self.new_partner() @@ -38,11 +38,11 @@ class PartnerCompanyCase(OnChangeCase): partner = self.new_partner() # User sets a name, which triggers onchanges - partner.name = u"Foó" + partner.name = "Foó" partner._onchange_name() # User unsets name, which triggers onchanges - partner.name = u"" + partner.name = "" partner._onchange_name() self.assertEqual(partner.firstname, False) @@ -52,7 +52,7 @@ class PartnerCompanyCase(OnChangeCase): class PartnerContactCase(OnChangeCase): def test_create_from_form_only_firstname(self): """A user creates a contact with only the firstname from the form.""" - firstname = u"Fïrst" + firstname = "Fïrst" with self.env.do_in_onchange(): # User presses ``new`` partner = self.new_partner() @@ -68,7 +68,7 @@ class PartnerContactCase(OnChangeCase): def test_create_from_form_only_lastname(self): """A user creates a contact with only the lastname from the form.""" - lastname = u"Läst" + lastname = "Läst" with self.env.do_in_onchange(): # User presses ``new`` partner = self.new_partner() @@ -84,8 +84,8 @@ class PartnerContactCase(OnChangeCase): def test_create_from_form_all(self): """A user creates a contact with all names from the form.""" - firstname = u"Fïrst" - lastname = u"Läst" + firstname = "Fïrst" + lastname = "Läst" with self.env.do_in_onchange(): # User presses ``new`` partner = self.new_partner() @@ -102,4 +102,4 @@ class PartnerContactCase(OnChangeCase): self.assertEqual(partner.lastname, lastname) self.assertEqual(partner.firstname, firstname) - self.assertEqual(partner.name, u" ".join((lastname, firstname))) + self.assertEqual(partner.name, " ".join((lastname, firstname))) diff --git a/partner_firstname/tests/test_order.py b/partner_firstname/tests/test_order.py index afc978b05..3a72b7fac 100644 --- a/partner_firstname/tests/test_order.py +++ b/partner_firstname/tests/test_order.py @@ -2,21 +2,21 @@ # © 2015 Antiun Ingenieria S.L. - Antonio Espinosa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.tests.common import TransactionCase +from odoo.tests.common import TransactionCase class PartnerNamesOrder(TransactionCase): def order_set(self, order): - return self.env['ir.config_parameter'].set_param( + return self.env['ir.config_parameter'].sudo().set_param( 'partner_names_order', order) def test_get_computed_name(self): - lastname = u"García Lorca" - firstname = u"Federico" + lastname = "García Lorca" + firstname = "Federico" cases = ( - ('last_first', u"García Lorca Federico"), - ('last_first_comma', u"García Lorca, Federico"), - ('first_last', u"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: @@ -26,12 +26,12 @@ class PartnerNamesOrder(TransactionCase): self.assertEqual(result, name) def test_get_inverse_name(self): - lastname = u"Flanker" - firstname = u"Petër" + lastname = "Flanker" + firstname = "Petër" cases = ( - ('last_first', u"Flanker Petër"), - ('last_first_comma', u"Flanker, Petër"), - ('first_last', u"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) diff --git a/partner_firstname/tests/test_user_onchange.py b/partner_firstname/tests/test_user_onchange.py index 4f0fa1052..fbf215ba8 100644 --- a/partner_firstname/tests/test_user_onchange.py +++ b/partner_firstname/tests/test_user_onchange.py @@ -9,7 +9,7 @@ class UserOnchangeCase(TransactionCase): def test_create_from_form_only_firstname(self): """In a new users form, a user set only the firstname.""" - firstname = u"Zoë" + firstname = "Zoë" with self.env.do_in_onchange(): # Changes firstname, which triggers onchanges self.user.firstname = firstname @@ -21,7 +21,7 @@ class UserOnchangeCase(TransactionCase): def test_create_from_form_only_lastname(self): """In a new user form, a user set only the lastname.""" - lastname = u"Żywioł" + lastname = "Żywioł" with self.env.do_in_onchange(): # Changes lastname, which triggers onchanges self.user.lastname = lastname @@ -33,8 +33,8 @@ class UserOnchangeCase(TransactionCase): def test_create_from_form_all(self): """In a new user form, a user set all names.""" - firstname = u"Zoë" - lastname = u"Żywioł" + firstname = "Zoë" + lastname = "Żywioł" with self.env.do_in_onchange(): # Changes firstname, which triggers onchanges self.user.firstname = firstname @@ -46,7 +46,7 @@ class UserOnchangeCase(TransactionCase): self.assertEqual(self.user.lastname, lastname) self.assertEqual(self.user.firstname, firstname) - self.assertEqual(self.user.name, u" ".join((lastname, firstname))) + self.assertEqual(self.user.name, " ".join((lastname, firstname))) def setUp(self): super(UserOnchangeCase, self).setUp() diff --git a/partner_firstname/views/base_config_view.xml b/partner_firstname/views/base_config_view.xml index 424b5d28f..b29910196 100644 --- a/partner_firstname/views/base_config_view.xml +++ b/partner_firstname/views/base_config_view.xml @@ -3,29 +3,32 @@ License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> - - Add partner_names_order config parameter - base.config.settings - - - - - - - - + + +