You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
2.4 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2015 Antiun Ingenieria S.L. - Antonio Espinosa
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. from openerp import models, fields, api
  6. _logger = logging.getLogger(__name__)
  7. class BaseConfigSettings(models.TransientModel):
  8. _inherit = 'base.config.settings'
  9. partner_names_order = fields.Selection(
  10. string="Partner names order",
  11. selection="_partner_names_order_selection",
  12. help="Order to compose partner fullname",
  13. required=True)
  14. partner_names_order_changed = fields.Boolean(
  15. readonly=True, compute="_compute_names_order_changed")
  16. def _partner_names_order_selection(self):
  17. return [
  18. ('last_first', 'Lastname Firstname'),
  19. ('last_first_comma', 'Lastname, Firstname'),
  20. ('first_last', 'Firstname Lastname'),
  21. ]
  22. def _partner_names_order_default(self):
  23. return self.env['res.partner']._names_order_default()
  24. @api.multi
  25. def get_default_partner_names_order(self):
  26. return {
  27. 'partner_names_order': self.env['ir.config_parameter'].get_param(
  28. 'partner_names_order', self._partner_names_order_default()),
  29. }
  30. @api.multi
  31. @api.depends('partner_names_order')
  32. def _compute_names_order_changed(self):
  33. current = self.env['ir.config_parameter'].get_param(
  34. 'partner_names_order', self._partner_names_order_default())
  35. for record in self:
  36. record.partner_names_order_changed = bool(
  37. record.partner_names_order != current
  38. )
  39. @api.onchange('partner_names_order')
  40. def _onchange_partner_names_order(self):
  41. self.partner_names_order_changed = self._compute_names_order_changed()
  42. @api.multi
  43. def set_partner_names_order(self):
  44. self.env['ir.config_parameter'].set_param(
  45. 'partner_names_order', self.partner_names_order)
  46. @api.multi
  47. def _partners_for_recalculating(self):
  48. return self.env['res.partner'].search([
  49. ('is_company', '=', False),
  50. ('firstname', '!=', False), ('lastname', '!=', False),
  51. ])
  52. @api.multi
  53. def action_recalculate_partners_name(self):
  54. partners = self._partners_for_recalculating()
  55. _logger.info("Recalculating names for %d partners.", len(partners))
  56. partners._compute_name()
  57. _logger.info("%d partners updated.", len(partners))
  58. return True