Browse Source

[MIG] partner_firstname

pull/487/head
Enric Tobella 7 years ago
parent
commit
01a92d1f54
  1. 4
      partner_firstname/README.rst
  2. 2
      partner_firstname/__manifest__.py
  3. 2
      partner_firstname/exceptions.py
  4. 4
      partner_firstname/i18n/es.po
  5. 2
      partner_firstname/i18n/fr.po
  6. 4
      partner_firstname/i18n/nl_NL.po
  7. 34
      partner_firstname/models/base_config_settings.py
  8. 18
      partner_firstname/models/res_partner.py
  9. 2
      partner_firstname/models/res_users.py
  10. 8
      partner_firstname/tests/base.py
  11. 14
      partner_firstname/tests/test_create.py
  12. 8
      partner_firstname/tests/test_defaults.py
  13. 2
      partner_firstname/tests/test_delete.py
  14. 10
      partner_firstname/tests/test_name.py
  15. 16
      partner_firstname/tests/test_onchange.py
  16. 24
      partner_firstname/tests/test_order.py
  17. 10
      partner_firstname/tests/test_user_onchange.py
  18. 29
      partner_firstname/views/base_config_view.xml

4
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:

2
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, "

2
partner_firstname/exceptions.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# © 2014-2015 Grupo ESOC (<http://www.grupoesoc.es>)
# 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):

4
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"

2
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 ""

4
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"

34
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):

18
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)

2
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)

8
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

14
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):

8
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):

2
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()

10
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():

16
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)))

24
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)

10
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()

29
partner_firstname/views/base_config_view.xml

@ -3,29 +3,32 @@
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record id="view_general_configuration" model="ir.ui.view">
<record id="view_general_configuration" model="ir.ui.view">
<field name="name">Add partner_names_order config parameter</field>
<field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="model">res.config.settings</field>
<field name="inherit_id"
ref="base_setup.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//label[@name='email_label']/.." position='after'>
<group>
<label for="partner_names_order" />
<div>
<div>
<field name="partner_names_order" class="oe_inline" />
<field name="partner_names_order_changed" invisible="1"/>
<xpath expr="//div[@name='multi_company']" position='after'>
<h2>Partner names order</h2>
<div class="row mt16 o_settings_container"
name="partner_names_order">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_right_pane">
<field name="partner_names_order"/>
<field name="partner_names_order_changed"
invisible="1"/>
<button name="action_recalculate_partners_name"
string="Recalculate names"
icon="fa-play"
type="object"
help="Recalculate names for all partners. This process could take so much time if there are more than 10,000 active partners"
attrs="{'invisible': [('partner_names_order_changed', '=', True)]}"/>
attrs="{'invisible': [('partner_names_order_changed', '=', False)]}"/>
</div>
</div>
</div>
</group>
</xpath>
</field>
</record>
</record>
</odoo>
Loading…
Cancel
Save