Browse Source

[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...
14.0
Laurent Mignon (ACSONE) 5 years ago
committed by Luis Torres
parent
commit
9a885bd69c
  1. 11
      partner_firstname/README.rst
  2. 27
      partner_firstname/i18n/partner_firstname.pot
  3. 37
      partner_firstname/models/base_config_settings.py
  4. 7
      partner_firstname/static/description/index.html
  5. 1
      partner_firstname/tests/__init__.py
  6. 35
      partner_firstname/tests/test_config_settings.py
  7. 7
      partner_firstname/tests/test_order.py
  8. 4
      partner_firstname/tests/test_user_form.py

11
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 :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github .. |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 :alt: OCA/partner-contact
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |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 :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |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 :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5| |badge1| |badge2| |badge3| |badge4| |badge5|
@ -81,7 +81,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/partner-contact/issues>`_.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_firstname%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_firstname%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -118,6 +118,7 @@ Contributors
* Pedro Baeza <pedro.baeza@serviciosbaeza.com> * Pedro Baeza <pedro.baeza@serviciosbaeza.com>
* Dave Lasley <dave@laslabs.com> * Dave Lasley <dave@laslabs.com>
* Graeme Gellatly <graeme@o4sb.com> * Graeme Gellatly <graeme@o4sb.com>
* Laurent Mignon <laurent.mignon@acsone.eu>
Maintainers 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 mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/12.0/partner_firstname>`_ project on GitHub.
This module is part of the `OCA/partner-contact <https://github.com/OCA/partner-contact/tree/13.0/partner_firstname>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

27
partner_firstname/i18n/partner_firstname.pot

@ -1,12 +1,12 @@
# Translation of Odoo Server. # Translation of Odoo Server.
# This file contains the translation of the following modules: # This file contains the translation of the following modules:
# * partner_firstname
# * partner_firstname
# #
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 12.0\n"
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
@ -14,8 +14,8 @@ msgstr ""
"Plural-Forms: \n" "Plural-Forms: \n"
#. module: partner_firstname #. 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 #, python-format
msgid "%s (copy)" msgid "%s (copy)"
msgstr "" msgstr ""
@ -31,12 +31,12 @@ msgid "Contact"
msgstr "" msgstr ""
#. module: partner_firstname #. 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." msgid "Contacts require a name."
msgstr "" msgstr ""
#. module: partner_firstname #. module: partner_firstname
#: code:addons/partner_firstname/exceptions.py:10
#: code:addons/partner_firstname/exceptions.py:0
#, python-format #, python-format
msgid "Error(s) with partner %d's name." msgid "Error(s) with partner %d's name."
msgstr "" msgstr ""
@ -60,7 +60,7 @@ msgid "Name"
msgstr "" msgstr ""
#. module: partner_firstname #. module: partner_firstname
#: code:addons/partner_firstname/exceptions.py:7
#: code:addons/partner_firstname/exceptions.py:0
#, python-format #, python-format
msgid "No name is set." msgid "No name is set."
msgstr "" msgstr ""
@ -71,7 +71,7 @@ msgid "Order to compose partner fullname"
msgstr "" msgstr ""
#. module: partner_firstname #. 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" msgid "Partner Names Order"
msgstr "" msgstr ""
@ -86,17 +86,18 @@ msgid "Partner names order"
msgstr "" msgstr ""
#. module: partner_firstname #. 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" msgid "Recalculate names"
msgstr "" msgstr ""
#. module: partner_firstname #. 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 "" msgstr ""
#. module: partner_firstname #. module: partner_firstname
#: model:ir.model,name:partner_firstname.model_res_users #: model:ir.model,name:partner_firstname.model_res_users
msgid "Users" msgid "Users"
msgstr "" msgstr ""

37
partner_firstname/models/base_config_settings.py

@ -3,7 +3,7 @@
import logging import logging
from odoo import api, fields, models
from odoo import fields, models
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -15,9 +15,14 @@ class ResConfigSettings(models.TransientModel):
string="Partner names order", string="Partner names order",
selection="_partner_names_order_selection", selection="_partner_names_order_selection",
help="Order to compose partner fullname", help="Order to compose partner fullname",
config_parameter="partner_names_order",
default=lambda a: a._partner_names_order_default(),
required=True, 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): def _partner_names_order_selection(self):
return [ return [
@ -29,21 +34,7 @@ class ResConfigSettings(models.TransientModel):
def _partner_names_order_default(self): 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()
)
)
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 = ( current = (
self.env["ir.config_parameter"] self.env["ir.config_parameter"]
.sudo() .sudo()
@ -56,16 +47,6 @@ class ResConfigSettings(models.TransientModel):
record.partner_names_order != current 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): def _partners_for_recalculating(self):
return self.env["res.partner"].search( return self.env["res.partner"].search(
[ [
@ -82,5 +63,7 @@ class ResConfigSettings(models.TransientModel):
partners = self._partners_for_recalculating() partners = self._partners_for_recalculating()
_logger.info("Recalculating names for %d partners.", len(partners)) _logger.info("Recalculating names for %d partners.", len(partners))
partners._compute_name() partners._compute_name()
self.partner_names_order_changed = False
self.execute()
_logger.info("%d partners updated.", len(partners)) _logger.info("%d partners updated.", len(partners))
return True return True

7
partner_firstname/static/description/index.html

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/partner-contact/tree/12.0/partner_firstname"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/partner-contact-12-0/partner-contact-12-0-partner_firstname"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/134/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/partner-contact/tree/13.0/partner_firstname"><img alt="OCA/partner-contact" src="https://img.shields.io/badge/github-OCA%2Fpartner--contact-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/partner-contact-13-0/partner-contact-13-0-partner_firstname"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/134/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module was written to extend the functionality of contacts to support <p>This module was written to extend the functionality of contacts to support
having separate last name and first name.</p> having separate last name and first name.</p>
<p><strong>Table of contents</strong></p> <p><strong>Table of contents</strong></p>
@ -426,7 +426,7 @@ as discussed at <a class="reference external" href="https://github.com/OCA/partn
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/partner-contact/issues">GitHub Issues</a>. <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/partner-contact/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported. 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 If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_firstname%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_firstname%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p> <p>Do not contact contributors directly about support or help with technical issues.</p>
</div> </div>
<div class="section" id="credits"> <div class="section" id="credits">
@ -462,6 +462,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<li>Pedro Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;serviciosbaeza.com">pedro.baeza&#64;serviciosbaeza.com</a>&gt;</li> <li>Pedro Baeza &lt;<a class="reference external" href="mailto:pedro.baeza&#64;serviciosbaeza.com">pedro.baeza&#64;serviciosbaeza.com</a>&gt;</li>
<li>Dave Lasley &lt;<a class="reference external" href="mailto:dave&#64;laslabs.com">dave&#64;laslabs.com</a>&gt;</li> <li>Dave Lasley &lt;<a class="reference external" href="mailto:dave&#64;laslabs.com">dave&#64;laslabs.com</a>&gt;</li>
<li>Graeme Gellatly &lt;<a class="reference external" href="mailto:graeme&#64;o4sb.com">graeme&#64;o4sb.com</a>&gt;</li> <li>Graeme Gellatly &lt;<a class="reference external" href="mailto:graeme&#64;o4sb.com">graeme&#64;o4sb.com</a>&gt;</li>
<li>Laurent Mignon &lt;<a class="reference external" href="mailto:laurent.mignon&#64;acsone.eu">laurent.mignon&#64;acsone.eu</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
@ -471,7 +472,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/partner-contact/tree/12.0/partner_firstname">OCA/partner-contact</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/partner-contact/tree/13.0/partner_firstname">OCA/partner-contact</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

1
partner_firstname/tests/__init__.py

@ -8,4 +8,5 @@ from . import (
test_user_form, test_user_form,
test_order, test_order,
test_copy, test_copy,
test_config_settings,
) )

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

7
partner_firstname/tests/test_order.py

@ -6,11 +6,8 @@ from odoo.tests.common import TransactionCase
class PartnerNamesOrder(TransactionCase): class PartnerNamesOrder(TransactionCase):
def order_set(self, order): 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): def test_get_computed_name(self):
lastname = "García Lorca" lastname = "García Lorca"

4
partner_firstname/tests/test_user_form.py

@ -53,7 +53,3 @@ class UserOnchangeCase(TransactionCase):
self.assertEqual(user_form.lastname, lastname) self.assertEqual(user_form.lastname, lastname)
self.assertEqual(user_form.firstname, firstname) self.assertEqual(user_form.firstname, firstname)
self.assertEqual(user_form.name, " ".join((firstname, lastname))) self.assertEqual(user_form.name, " ".join((firstname, lastname)))
def setUp(self):
super(UserOnchangeCase, self).setUp()
self.user = self.env["res.users"].new()
Loading…
Cancel
Save