From 9a885bd69c887b6f0464b5933c9d310103474c42 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 7 Nov 2019 21:30:36 +0100 Subject: [PATCH] [MIG] partner_firstname: Fix config settings Display the recompute button only after saving the settings if the order hase changed. Once the recompute is done, the buttons desapears. Bedore this change it was not possible to recompute the partner names order since the button was only displayed after changing the order value but before saving the changes. When clicked, an error message was displayed since the action will force the reload of the page before saving the values... --- partner_firstname/README.rst | 11 +++--- partner_firstname/i18n/partner_firstname.pot | 27 +++++++------- .../models/base_config_settings.py | 37 +++++-------------- .../static/description/index.html | 7 ++-- partner_firstname/tests/__init__.py | 1 + .../tests/test_config_settings.py | 35 ++++++++++++++++++ partner_firstname/tests/test_order.py | 7 +--- partner_firstname/tests/test_user_form.py | 4 -- 8 files changed, 72 insertions(+), 57 deletions(-) create mode 100644 partner_firstname/tests/test_config_settings.py diff --git a/partner_firstname/README.rst b/partner_firstname/README.rst index dca4da88b..c481c6caa 100644 --- a/partner_firstname/README.rst +++ b/partner_firstname/README.rst @@ -14,13 +14,13 @@ Partner first name and last name :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github - :target: https://github.com/OCA/partner-contact/tree/12.0/partner_firstname + :target: https://github.com/OCA/partner-contact/tree/13.0/partner_firstname :alt: OCA/partner-contact .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-partner_firstname + :target: https://translation.odoo-community.org/projects/partner-contact-13-0/partner-contact-13-0-partner_firstname :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/134/12.0 + :target: https://runbot.odoo-community.org/runbot/134/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -81,7 +81,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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -118,6 +118,7 @@ Contributors * Pedro Baeza * Dave Lasley * Graeme Gellatly +* Laurent Mignon Maintainers ~~~~~~~~~~~ @@ -132,6 +133,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/partner-contact `_ project on GitHub. +This module is part of the `OCA/partner-contact `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/partner_firstname/i18n/partner_firstname.pot b/partner_firstname/i18n/partner_firstname.pot index 267a0e3cb..70b4fc595 100644 --- a/partner_firstname/i18n/partner_firstname.pot +++ b/partner_firstname/i18n/partner_firstname.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * partner_firstname +# * partner_firstname # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -14,8 +14,8 @@ msgstr "" "Plural-Forms: \n" #. module: partner_firstname -#: code:addons/partner_firstname/models/res_users.py:40 -#: code:addons/partner_firstname/models/res_users.py:42 +#: code:addons/partner_firstname/models/res_users.py:0 +#: code:addons/partner_firstname/models/res_users.py:0 #, python-format msgid "%s (copy)" msgstr "" @@ -31,12 +31,12 @@ msgid "Contact" msgstr "" #. module: partner_firstname -#: sql_constraint:res.partner:0 +#: model:ir.model.constraint,message:partner_firstname.constraint_res_partner_check_name msgid "Contacts require a name." msgstr "" #. module: partner_firstname -#: code:addons/partner_firstname/exceptions.py:10 +#: code:addons/partner_firstname/exceptions.py:0 #, python-format msgid "Error(s) with partner %d's name." msgstr "" @@ -60,7 +60,7 @@ msgid "Name" msgstr "" #. module: partner_firstname -#: code:addons/partner_firstname/exceptions.py:7 +#: code:addons/partner_firstname/exceptions.py:0 #, python-format msgid "No name is set." msgstr "" @@ -71,7 +71,7 @@ msgid "Order to compose partner fullname" msgstr "" #. module: partner_firstname -#: model_terms:ir.ui.view,arch_db:partner_firstname.view_general_configuration +#: model_terms:ir.ui.view,arch_db:partner_firstname.res_config_settings_view_form msgid "Partner Names Order" msgstr "" @@ -86,17 +86,18 @@ msgid "Partner names order" msgstr "" #. module: partner_firstname -#: model_terms:ir.ui.view,arch_db:partner_firstname.view_general_configuration +#: model_terms:ir.ui.view,arch_db:partner_firstname.res_config_settings_view_form msgid "Recalculate names" msgstr "" #. module: partner_firstname -#: model_terms:ir.ui.view,arch_db:partner_firstname.view_general_configuration -msgid "Recalculate names for all partners. This process could take so much time if there are more than 10,000 active partners" +#: model_terms:ir.ui.view,arch_db:partner_firstname.res_config_settings_view_form +msgid "" +"Recalculate names for all partners. This process could take so much time if " +"there are more than 10,000 active partners" msgstr "" #. module: partner_firstname #: model:ir.model,name:partner_firstname.model_res_users msgid "Users" msgstr "" - diff --git a/partner_firstname/models/base_config_settings.py b/partner_firstname/models/base_config_settings.py index d02040049..76c2f1f91 100644 --- a/partner_firstname/models/base_config_settings.py +++ b/partner_firstname/models/base_config_settings.py @@ -3,7 +3,7 @@ import logging -from odoo import api, fields, models +from odoo import fields, models _logger = logging.getLogger(__name__) @@ -15,9 +15,14 @@ class ResConfigSettings(models.TransientModel): string="Partner names order", selection="_partner_names_order_selection", help="Order to compose partner fullname", + config_parameter="partner_names_order", + default=lambda a: a._partner_names_order_default(), required=True, + inverse="_inverse_partner_names_order", + ) + partner_names_order_changed = fields.Boolean( + config_parameter="partner_names_order_changed" ) - partner_names_order_changed = fields.Boolean(compute="_compute_names_order_changed") def _partner_names_order_selection(self): return [ @@ -29,21 +34,7 @@ class ResConfigSettings(models.TransientModel): def _partner_names_order_default(self): 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() - ) - ) - res.update(partner_names_order=partner_names_order) - return res - - @api.depends("partner_names_order") - def _compute_names_order_changed(self): + def _inverse_partner_names_order(self): current = ( self.env["ir.config_parameter"] .sudo() @@ -56,16 +47,6 @@ class ResConfigSettings(models.TransientModel): record.partner_names_order != current ) - @api.onchange("partner_names_order") - def _onchange_partner_names_order(self): - self._compute_names_order_changed() - - def set_values(self): - super(ResConfigSettings, self).set_values() - self.env["ir.config_parameter"].sudo().set_param( - "partner_names_order", self.partner_names_order - ) - def _partners_for_recalculating(self): return self.env["res.partner"].search( [ @@ -82,5 +63,7 @@ class ResConfigSettings(models.TransientModel): partners = self._partners_for_recalculating() _logger.info("Recalculating names for %d partners.", len(partners)) partners._compute_name() + self.partner_names_order_changed = False + self.execute() _logger.info("%d partners updated.", len(partners)) return True diff --git a/partner_firstname/static/description/index.html b/partner_firstname/static/description/index.html index 6b5583364..d9e8e781c 100644 --- a/partner_firstname/static/description/index.html +++ b/partner_firstname/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runbot

+

Beta License: AGPL-3 OCA/partner-contact Translate me on Weblate Try me on Runbot

This module was written to extend the functionality of contacts to support having separate last name and first name.

Table of contents

@@ -426,7 +426,7 @@ as discussed at 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.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -462,6 +462,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
  • Pedro Baeza <pedro.baeza@serviciosbaeza.com>
  • Dave Lasley <dave@laslabs.com>
  • Graeme Gellatly <graeme@o4sb.com>
  • +
  • Laurent Mignon <laurent.mignon@acsone.eu>
  • @@ -471,7 +472,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

    OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

    -

    This module is part of the OCA/partner-contact project on GitHub.

    +

    This module is part of the OCA/partner-contact project on GitHub.

    You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

    diff --git a/partner_firstname/tests/__init__.py b/partner_firstname/tests/__init__.py index bb102a3ac..573ff3228 100644 --- a/partner_firstname/tests/__init__.py +++ b/partner_firstname/tests/__init__.py @@ -8,4 +8,5 @@ from . import ( test_user_form, test_order, test_copy, + test_config_settings, ) diff --git a/partner_firstname/tests/test_config_settings.py b/partner_firstname/tests/test_config_settings.py new file mode 100644 index 000000000..7230ceaa3 --- /dev/null +++ b/partner_firstname/tests/test_config_settings.py @@ -0,0 +1,35 @@ +# Copyright 2015 Antiun Ingenieria S.L. - Antonio Espinosa +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo.tests.common import SavepointCase + + +class TestConfigSettings(SavepointCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.config = cls.env["res.config.settings"].create({}) + + def _change_partner_names_order(self): + orders = [o[0] for o in self.config._partner_names_order_selection()] + current = new = self.config.partner_names_order + for o in orders: + if o != current: + new = o + break + self.config.partner_names_order = new + + def test_partner_names_order_changed(self): + # The partner_names_order_changed is set to true at save time when + # the value of partner_names_order is updated + self.assertFalse(self.config.partner_names_order_changed) + self._change_partner_names_order() + self.assertTrue(self.config.partner_names_order_changed) + + def test_partner_names_order_changed_reset(self): + # The partner_names_order_changed is reset to false when + # the action action_recalculate_partners_name is executed + self._change_partner_names_order() + self.assertTrue(self.config.partner_names_order_changed) + self.config.action_recalculate_partners_name() + self.assertFalse(self.config.partner_names_order_changed) diff --git a/partner_firstname/tests/test_order.py b/partner_firstname/tests/test_order.py index b21eec816..4c93794f6 100644 --- a/partner_firstname/tests/test_order.py +++ b/partner_firstname/tests/test_order.py @@ -6,11 +6,8 @@ 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) - ) + config = self.env["res.config.settings"].create({"partner_names_order": order}) + config.execute() def test_get_computed_name(self): lastname = "GarcĂ­a Lorca" diff --git a/partner_firstname/tests/test_user_form.py b/partner_firstname/tests/test_user_form.py index e3d250565..5abb10b99 100644 --- a/partner_firstname/tests/test_user_form.py +++ b/partner_firstname/tests/test_user_form.py @@ -53,7 +53,3 @@ class UserOnchangeCase(TransactionCase): 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()