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.

86 lines
3.2 KiB

10 years ago
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Odoo, Open Source Management Solution
  5. # This module copyright (C) 2015 Savoir-faire Linux
  6. # (<http://www.savoirfairelinux.com>).
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License as
  10. # published by the Free Software Foundation, either version 3 of the
  11. # License, or (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU Affero General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU Affero General Public License
  19. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. ##############################################################################
  22. from openerp.osv import orm, fields
  23. class IrActionsReportXml(orm.Model):
  24. _inherit = 'ir.actions.report.xml'
  25. def _compute_smart_name(self, cr, uid, ids, fields, arg, context=None):
  26. if context is None:
  27. context = {}
  28. else:
  29. context = context.copy()
  30. context["preserve_name"] = True
  31. company = self.pool['res.users'].browse(
  32. cr, uid, uid, context=context).company_id
  33. logo_name = (
  34. company.name_secondary
  35. if company.has_logo_secondary
  36. else False
  37. )
  38. res = {}
  39. for rec in self.browse(cr, uid, ids, context=context):
  40. if logo_name and rec.use_secondary_logo:
  41. res[rec.id] = ' '.join([rec.name.rstrip(), logo_name])
  42. else:
  43. res[rec.id] = rec.name
  44. return res
  45. _columns = {
  46. 'use_secondary_logo': fields.boolean('Use Secondary Logo'),
  47. 'smart_name': fields.function(
  48. _compute_smart_name,
  49. string="Name", type="char",
  50. ),
  51. }
  52. _defaults = {
  53. 'use_secondary_logo': False
  54. }
  55. def read(self, cr, uid, ids, fields, context=None, load="_classic_read"):
  56. if any((context and context.get("preserve_name"),
  57. fields and "name" not in fields)):
  58. # Make sure not to compute smart_name unless necessary.
  59. # Also: prevent infinite recursion
  60. return super(IrActionsReportXml, self).read(cr, uid, ids,
  61. fields=fields,
  62. context=context,
  63. load=load)
  64. if fields and "name" in fields and "smart_name" not in fields:
  65. fields.append("smart_name")
  66. res = super(IrActionsReportXml, self).read(cr, uid, ids,
  67. fields=fields,
  68. context=context,
  69. load=load)
  70. if isinstance(ids, (int, long)):
  71. target = [res]
  72. else:
  73. target = res
  74. for d in target:
  75. d["name"] = d["smart_name"]
  76. return res