From fcf5e95c08d269bb2f6fc9c5930d8266373ea780 Mon Sep 17 00:00:00 2001 From: Dave Lasley Date: Sun, 13 Nov 2016 15:53:24 -0800 Subject: [PATCH] [MIG] partner_firstname: Upgrade to v10 * Prefer odoo to openerp & remove data tags * Move exceptions file out of models * Fix string selection in xpath * Rename res_users and add import * Fix api mismatches * Add missing param * Alphabetize imports * Remove readonly from computed field * Remove deprecated api.one * Add Tecnativa * Fix icon * Fix singleton issue * Add depends to compute --- partner_firstname/README.rst | 6 +-- partner_firstname/__manifest__.py | 2 + partner_firstname/{models => }/exceptions.py | 0 partner_firstname/models/__init__.py | 1 + .../models/base_config_settings.py | 26 +++++++---- partner_firstname/models/res_partner.py | 45 +++++++++++-------- .../models/{res_user.py => res_users.py} | 0 partner_firstname/tests/base.py | 2 +- partner_firstname/tests/test_empty.py | 2 +- partner_firstname/views/base_config_view.xml | 11 ++--- 10 files changed, 57 insertions(+), 38 deletions(-) rename partner_firstname/{models => }/exceptions.py (100%) rename partner_firstname/models/{res_user.py => res_users.py} (100%) diff --git a/partner_firstname/README.rst b/partner_firstname/README.rst index 224535347..2b045f04f 100644 --- a/partner_firstname/README.rst +++ b/partner_firstname/README.rst @@ -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/8.0 + :target: https://runbot.odoo-community.org/runbot/134/10.0 For further information, please visit: @@ -68,8 +68,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed feedback `here -`_. +help us smashing it by providing a detailed and welcomed feedback. Credits ======= @@ -93,6 +92,7 @@ Contributors * Ronald Portier * Sylvain Van Hoof * Pedro Baeza +* Dave Lasley Translations ------------ diff --git a/partner_firstname/__manifest__.py b/partner_firstname/__manifest__.py index c14de355c..da5c33ebe 100644 --- a/partner_firstname/__manifest__.py +++ b/partner_firstname/__manifest__.py @@ -10,6 +10,8 @@ 'version': '10.0.2.0.0', 'author': "Camptocamp, " "Grupo ESOC Ingeniería de Servicios, " + "Tecnativa, " + "LasLabs, " "Odoo Community Association (OCA)", 'license': "AGPL-3", 'maintainer': 'Camptocamp, Acsone', diff --git a/partner_firstname/models/exceptions.py b/partner_firstname/exceptions.py similarity index 100% rename from partner_firstname/models/exceptions.py rename to partner_firstname/exceptions.py diff --git a/partner_firstname/models/__init__.py b/partner_firstname/models/__init__.py index aa04cb891..05e809bb7 100644 --- a/partner_firstname/models/__init__.py +++ b/partner_firstname/models/__init__.py @@ -4,3 +4,4 @@ from . import base_config_settings from . import res_partner +from . import res_users diff --git a/partner_firstname/models/base_config_settings.py b/partner_firstname/models/base_config_settings.py index e79b9d5dd..35d2b52fe 100644 --- a/partner_firstname/models/base_config_settings.py +++ b/partner_firstname/models/base_config_settings.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). import logging -from openerp import models, fields, api +from openerp import api, fields, models _logger = logging.getLogger(__name__) @@ -14,9 +14,11 @@ class BaseConfigSettings(models.TransientModel): string="Partner names order", selection="_partner_names_order_selection", help="Order to compose partner fullname", - required=True) + required=True, + ) partner_names_order_changed = fields.Boolean( - readonly=True, compute="_compute_names_order_changed") + compute="_compute_names_order_changed", + ) def _partner_names_order_selection(self): return [ @@ -25,22 +27,30 @@ class BaseConfigSettings(models.TransientModel): ('first_last', 'Firstname Lastname'), ] + @api.multi def _partner_names_order_default(self): return self.env['res.partner']._names_order_default() - @api.multi - def get_default_partner_names_order(self): + @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()), + 'partner_names_order', self._partner_names_order_default(), + ), } @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()) - return self.partner_names_order != current + 'partner_names_order', self._partner_names_order_default(), + ) + for record in self: + record.partner_names_order_changed = bool( + record.partner_names_order != current + ) + @api.multi @api.onchange('partner_names_order') def _onchange_partner_names_order(self): self.partner_names_order_changed = self._compute_names_order_changed() diff --git a/partner_firstname/models/res_partner.py b/partner_firstname/models/res_partner.py index ff721d462..d576e6729 100644 --- a/partner_firstname/models/res_partner.py +++ b/partner_firstname/models/res_partner.py @@ -99,29 +99,33 @@ class ResPartner(models.Model): else: return u" ".join((p for p in (lastname, firstname) if p)) - @api.one + @api.multi @api.depends("firstname", "lastname") def _compute_name(self): """Write the 'name' field according to splitted data.""" - self.name = self._get_computed_name(self.lastname, self.firstname) + for record in self: + record.name = record._get_computed_name( + record.lastname, record.firstname, + ) - @api.one + @api.multi def _inverse_name_after_cleaning_whitespace(self): """Clean whitespace in :attr:`~.name` and split it. The splitting logic is stored separately in :meth:`~._inverse_name`, so submodules can extend that method and get whitespace cleaning for free. """ - # Remove unneeded whitespace - clean = self._get_whitespace_cleaned_name(self.name) + for record in self: + # Remove unneeded whitespace + clean = record._get_whitespace_cleaned_name(record.name) - # Clean name avoiding infinite recursion - if self.name != clean: - self.name = clean + # Clean name avoiding infinite recursion + if record.name != clean: + record.name = clean - # Save name in the real fields - else: - self._inverse_name() + # Save name in the real fields + else: + record._inverse_name() @api.model def _get_whitespace_cleaned_name(self, name, comma=False): @@ -170,19 +174,24 @@ class ResPartner(models.Model): parts.append(False) return {"lastname": parts[0], "firstname": parts[1]} - @api.one + @api.multi def _inverse_name(self): """Try to revert the effect of :meth:`._compute_name`.""" - parts = self._get_inverse_name(self.name, self.is_company) - self.lastname, self.firstname = parts["lastname"], parts["firstname"] + for record in self: + parts = record._get_inverse_name(record.name, record.is_company) + record.lastname = parts['lastname'] + record.firstname = parts['firstname'] - @api.one + @api.multi @api.constrains("firstname", "lastname") def _check_name(self): """Ensure at least one name is set.""" - if ((self.type == 'contact' or self.is_company) and - not (self.firstname or self.lastname)): - raise exceptions.EmptyNamesError(self) + for record in self: + if all(( + record.type == 'contact' or record.is_company, + not (record.firstname or record.lastname) + )): + raise exceptions.EmptyNamesError(record) @api.onchange("firstname", "lastname") def _onchange_subnames(self): diff --git a/partner_firstname/models/res_user.py b/partner_firstname/models/res_users.py similarity index 100% rename from partner_firstname/models/res_user.py rename to partner_firstname/models/res_users.py diff --git a/partner_firstname/tests/base.py b/partner_firstname/tests/base.py index a5faaa958..c6236c866 100644 --- a/partner_firstname/tests/base.py +++ b/partner_firstname/tests/base.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo.tests.common import TransactionCase -from ..models import exceptions as ex +from .. import exceptions as ex class MailInstalled(): diff --git a/partner_firstname/tests/test_empty.py b/partner_firstname/tests/test_empty.py index a36642677..00e51f930 100644 --- a/partner_firstname/tests/test_empty.py +++ b/partner_firstname/tests/test_empty.py @@ -8,7 +8,7 @@ To have more accurate results, remove the ``mail`` module before testing. """ from odoo.tests.common import TransactionCase from .base import MailInstalled -from ..models import exceptions as ex +from .. import exceptions as ex class CompanyCase(TransactionCase): diff --git a/partner_firstname/views/base_config_view.xml b/partner_firstname/views/base_config_view.xml index f78b0a10f..424b5d28f 100644 --- a/partner_firstname/views/base_config_view.xml +++ b/partner_firstname/views/base_config_view.xml @@ -1,15 +1,14 @@ - - + Add partner_names_order config parameter base.config.settings - +