Browse Source

[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
14.0
Dave Lasley 8 years ago
committed by Luis Torres
parent
commit
d834d49508
  1. 6
      partner_firstname/README.rst
  2. 2
      partner_firstname/__manifest__.py
  3. 0
      partner_firstname/exceptions.py
  4. 1
      partner_firstname/models/__init__.py
  5. 26
      partner_firstname/models/base_config_settings.py
  6. 45
      partner_firstname/models/res_partner.py
  7. 0
      partner_firstname/models/res_users.py
  8. 2
      partner_firstname/tests/base.py
  9. 2
      partner_firstname/tests/test_empty.py
  10. 11
      partner_firstname/views/base_config_view.xml

6
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 .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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: For further information, please visit:
@ -68,8 +68,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues Bugs are tracked on `GitHub Issues
<https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please <https://github.com/OCA/partner-contact/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first, 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
<https://github.com/OCA/partner-contact/issues/new?body=module:%20partner_firstname%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
help us smashing it by providing a detailed and welcomed feedback.
Credits Credits
======= =======
@ -93,6 +92,7 @@ Contributors
* Ronald Portier <ronald@therp.nl> * Ronald Portier <ronald@therp.nl>
* Sylvain Van Hoof * Sylvain Van Hoof
* Pedro Baeza <pedro.baeza@serviciosbaeza.com> * Pedro Baeza <pedro.baeza@serviciosbaeza.com>
* Dave Lasley <dave@laslabs.com>
Translations Translations
------------ ------------

2
partner_firstname/__manifest__.py

@ -10,6 +10,8 @@
'version': '10.0.2.0.0', 'version': '10.0.2.0.0',
'author': "Camptocamp, " 'author': "Camptocamp, "
"Grupo ESOC Ingeniería de Servicios, " "Grupo ESOC Ingeniería de Servicios, "
"Tecnativa, "
"LasLabs, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
'license': "AGPL-3", 'license': "AGPL-3",
'maintainer': 'Camptocamp, Acsone', 'maintainer': 'Camptocamp, Acsone',

0
partner_firstname/models/exceptions.py → partner_firstname/exceptions.py

1
partner_firstname/models/__init__.py

@ -4,3 +4,4 @@
from . import base_config_settings from . import base_config_settings
from . import res_partner from . import res_partner
from . import res_users

26
partner_firstname/models/base_config_settings.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import logging import logging
from openerp import models, fields, api
from openerp import api, fields, models
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
@ -14,9 +14,11 @@ class BaseConfigSettings(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",
required=True)
required=True,
)
partner_names_order_changed = fields.Boolean( partner_names_order_changed = fields.Boolean(
readonly=True, compute="_compute_names_order_changed")
compute="_compute_names_order_changed",
)
def _partner_names_order_selection(self): def _partner_names_order_selection(self):
return [ return [
@ -25,22 +27,30 @@ class BaseConfigSettings(models.TransientModel):
('first_last', 'Firstname Lastname'), ('first_last', 'Firstname Lastname'),
] ]
@api.multi
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.multi
def get_default_partner_names_order(self):
@api.model
def get_default_partner_names_order(self, fields):
return { return {
'partner_names_order': self.env['ir.config_parameter'].get_param( '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.multi
@api.depends('partner_names_order')
def _compute_names_order_changed(self): def _compute_names_order_changed(self):
current = self.env['ir.config_parameter'].get_param( 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') @api.onchange('partner_names_order')
def _onchange_partner_names_order(self): def _onchange_partner_names_order(self):
self.partner_names_order_changed = self._compute_names_order_changed() self.partner_names_order_changed = self._compute_names_order_changed()

45
partner_firstname/models/res_partner.py

@ -99,29 +99,33 @@ class ResPartner(models.Model):
else: else:
return u" ".join((p for p in (lastname, firstname) if p)) return u" ".join((p for p in (lastname, firstname) if p))
@api.one
@api.multi
@api.depends("firstname", "lastname") @api.depends("firstname", "lastname")
def _compute_name(self): def _compute_name(self):
"""Write the 'name' field according to splitted data.""" """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): def _inverse_name_after_cleaning_whitespace(self):
"""Clean whitespace in :attr:`~.name` and split it. """Clean whitespace in :attr:`~.name` and split it.
The splitting logic is stored separately in :meth:`~._inverse_name`, so The splitting logic is stored separately in :meth:`~._inverse_name`, so
submodules can extend that method and get whitespace cleaning for free. 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 @api.model
def _get_whitespace_cleaned_name(self, name, comma=False): def _get_whitespace_cleaned_name(self, name, comma=False):
@ -170,19 +174,24 @@ class ResPartner(models.Model):
parts.append(False) parts.append(False)
return {"lastname": parts[0], "firstname": parts[1]} return {"lastname": parts[0], "firstname": parts[1]}
@api.one
@api.multi
def _inverse_name(self): def _inverse_name(self):
"""Try to revert the effect of :meth:`._compute_name`.""" """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") @api.constrains("firstname", "lastname")
def _check_name(self): def _check_name(self):
"""Ensure at least one name is set.""" """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") @api.onchange("firstname", "lastname")
def _onchange_subnames(self): def _onchange_subnames(self):

0
partner_firstname/models/res_user.py → partner_firstname/models/res_users.py

2
partner_firstname/tests/base.py

@ -3,7 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests.common import TransactionCase from odoo.tests.common import TransactionCase
from ..models import exceptions as ex
from .. import exceptions as ex
class MailInstalled(): class MailInstalled():

2
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 odoo.tests.common import TransactionCase
from .base import MailInstalled from .base import MailInstalled
from ..models import exceptions as ex
from .. import exceptions as ex
class CompanyCase(TransactionCase): class CompanyCase(TransactionCase):

11
partner_firstname/views/base_config_view.xml

@ -1,15 +1,14 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- © 2015 Antiun Ingenieria S.L. - Antonio Espinosa <!-- © 2015 Antiun Ingenieria S.L. - Antonio Espinosa
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<openerp>
<data>
<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="name">Add partner_names_order config parameter</field>
<field name="model">base.config.settings</field> <field name="model">base.config.settings</field>
<field name="inherit_id" ref="base_setup.view_general_configuration"/> <field name="inherit_id" ref="base_setup.view_general_configuration"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//label[@string='Email']/.." position='after'>
<xpath expr="//label[@name='email_label']/.." position='after'>
<group> <group>
<label for="partner_names_order" /> <label for="partner_names_order" />
<div> <div>
@ -18,7 +17,7 @@
<field name="partner_names_order_changed" invisible="1"/> <field name="partner_names_order_changed" invisible="1"/>
<button name="action_recalculate_partners_name" <button name="action_recalculate_partners_name"
string="Recalculate names" string="Recalculate names"
icon="gtk-execute"
icon="fa-play"
type="object" type="object"
help="Recalculate names for all partners. This process could take so much time if there are more than 10,000 active partners" 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', '=', True)]}"/>
@ -29,6 +28,4 @@
</field> </field>
</record> </record>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save