Browse Source
Merge pull request #333 from LasLabs/feature/9.0/partner_firstname-configurable-order
Merge pull request #333 from LasLabs/feature/9.0/partner_firstname-configurable-order
[IMP][9.0] Partner names order configurablepull/403/head
Pedro M. Baeza
8 years ago
committed by
GitHub
12 changed files with 244 additions and 28 deletions
-
52partner_firstname/README.rst
-
11partner_firstname/__openerp__.py
-
6partner_firstname/models/__init__.py
-
70partner_firstname/models/base_config_settings.py
-
40partner_firstname/models/res_partner.py
-
0partner_firstname/models/res_users.py
-
3partner_firstname/tests/__init__.py
-
1partner_firstname/tests/test_create.py
-
40partner_firstname/tests/test_order.py
-
31partner_firstname/views/base_config_view.xml
-
6partner_firstname/views/res_partner.xml
-
6partner_firstname/views/res_user.xml
@ -1,5 +1,7 @@ |
|||
# -*- 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 |
|||
from . import res_users |
@ -0,0 +1,70 @@ |
|||
# -*- 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 |
|||
@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()) |
|||
for record in self: |
|||
record.partner_names_order_changed = bool( |
|||
record.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,31 @@ |
|||
<?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). --> |
|||
<odoo> |
|||
|
|||
<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[@name='email_label']/.." 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="fa-play" |
|||
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> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue