Antonio Espinosa
9 years ago
committed by
Jairo Llopis
12 changed files with 239 additions and 22 deletions
-
52partner_firstname/README.rst
-
10partner_firstname/__manifest__.py
-
5partner_firstname/models/__init__.py
-
66partner_firstname/models/base_config_settings.py
-
0partner_firstname/models/exceptions.py
-
40partner_firstname/models/res_partner.py
-
3partner_firstname/tests/__init__.py
-
2partner_firstname/tests/base.py
-
1partner_firstname/tests/test_create.py
-
2partner_firstname/tests/test_empty.py
-
40partner_firstname/tests/test_order.py
-
34partner_firstname/views/base_config_view.xml
@ -1,5 +1,6 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2013 Nicolas Bessi (Camptocamp SA) |
|||
# © 2015 Antiun Ingenieria S.L. - Antonio Espinosa |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
from . import base_config_settings |
|||
from . import res_partner |
|||
from . import res_user |
@ -0,0 +1,66 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2015 Antiun Ingenieria S.L. - Antonio Espinosa |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
import logging |
|||
from openerp import models, fields, api |
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
|
|||
class BaseConfigSettings(models.TransientModel): |
|||
_inherit = 'base.config.settings' |
|||
|
|||
partner_names_order = fields.Selection( |
|||
string="Partner names order", |
|||
selection="_partner_names_order_selection", |
|||
help="Order to compose partner fullname", |
|||
required=True) |
|||
partner_names_order_changed = fields.Boolean( |
|||
readonly=True, compute="_compute_names_order_changed") |
|||
|
|||
def _partner_names_order_selection(self): |
|||
return [ |
|||
('last_first', 'Lastname Firstname'), |
|||
('last_first_comma', 'Lastname, Firstname'), |
|||
('first_last', 'Firstname Lastname'), |
|||
] |
|||
|
|||
def _partner_names_order_default(self): |
|||
return self.env['res.partner']._names_order_default() |
|||
|
|||
@api.multi |
|||
def get_default_partner_names_order(self): |
|||
return { |
|||
'partner_names_order': self.env['ir.config_parameter'].get_param( |
|||
'partner_names_order', self._partner_names_order_default()), |
|||
} |
|||
|
|||
@api.multi |
|||
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 |
|||
|
|||
@api.onchange('partner_names_order') |
|||
def _onchange_partner_names_order(self): |
|||
self.partner_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) |
|||
|
|||
@api.multi |
|||
def _partners_for_recalculating(self): |
|||
return self.env['res.partner'].search([ |
|||
('is_company', '=', False), |
|||
('firstname', '!=', False), ('lastname', '!=', False), |
|||
]) |
|||
|
|||
@api.multi |
|||
def action_recalculate_partners_name(self): |
|||
partners = self._partners_for_recalculating() |
|||
_logger.info("Recalculating names for %d partners.", len(partners)) |
|||
partners._compute_name() |
|||
_logger.info("%d partners updated.", len(partners)) |
|||
return True |
@ -0,0 +1,40 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 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 |
|||
|
|||
|
|||
class PartnerNamesOrder(TransactionCase): |
|||
def order_set(self, order): |
|||
return self.env['ir.config_parameter'].set_param( |
|||
'partner_names_order', order) |
|||
|
|||
def test_get_computed_name(self): |
|||
lastname = u"García Lorca" |
|||
firstname = u"Federico" |
|||
cases = ( |
|||
('last_first', u"García Lorca Federico"), |
|||
('last_first_comma', u"García Lorca, Federico"), |
|||
('first_last', u"Federico García Lorca"), |
|||
) |
|||
|
|||
for order, name in cases: |
|||
self.order_set(order) |
|||
result = self.env['res.partner']._get_computed_name( |
|||
lastname, firstname) |
|||
self.assertEqual(result, name) |
|||
|
|||
def test_get_inverse_name(self): |
|||
lastname = u"Flanker" |
|||
firstname = u"Petër" |
|||
cases = ( |
|||
('last_first', u"Flanker Petër"), |
|||
('last_first_comma', u"Flanker, Petër"), |
|||
('first_last', u"Petër Flanker"), |
|||
) |
|||
for order, name in cases: |
|||
self.order_set(order) |
|||
result = self.env['res.partner']._get_inverse_name(name) |
|||
self.assertEqual(result['lastname'], lastname) |
|||
self.assertEqual(result['firstname'], firstname) |
@ -0,0 +1,34 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<!-- © 2015 Antiun Ingenieria S.L. - Antonio Espinosa |
|||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). --> |
|||
<openerp> |
|||
<data> |
|||
|
|||
<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="arch" type="xml"> |
|||
<xpath expr="//label[@string='Email']/.." 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"/> |
|||
<button name="action_recalculate_partners_name" |
|||
string="Recalculate names" |
|||
icon="gtk-execute" |
|||
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)]}"/> |
|||
</div> |
|||
</div> |
|||
</group> |
|||
</xpath> |
|||
</field> |
|||
</record> |
|||
|
|||
|
|||
</data> |
|||
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue