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.

98 lines
3.5 KiB

10 years ago
10 years ago
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. from openerp import tools
  24. class ResCompany(orm.Model):
  25. _inherit = 'res.company'
  26. def _get_logo_secondary(self, cr, uid, ids, name, args, context=None):
  27. result = dict.fromkeys(ids, False)
  28. for obj in self.browse(cr, uid, ids, context=context):
  29. result[obj.id] = tools.image_get_resized_images(obj.logo_secondary)
  30. return result
  31. def _set_logo_secondary(
  32. self, cr, uid, id, name, value, args, context=None):
  33. return self.write(
  34. cr, uid, [id],
  35. {'image': tools.image_resize_image_big(value)},
  36. context=context
  37. )
  38. def _has_logo_secondary(self, cr, uid, ids, name, args, context=None):
  39. result = {}
  40. for obj in self.browse(cr, uid, ids, context=context):
  41. result[obj.id] = obj.logo_secondary is not False
  42. return result
  43. def _get_smart_logo(self, cr, uid, ids, name, args, context=None):
  44. context = context or None
  45. res = {}
  46. for obj in self.browse(cr, uid, ids, context=context):
  47. if 'use_secondary_logo' in context and context[
  48. 'use_secondary_logo']:
  49. res[obj.id] = obj.logo_secondary
  50. else:
  51. res[obj.id] = obj.logo
  52. return res
  53. _columns = {
  54. 'name_secondary': fields.char('Secondary name', size=128),
  55. 'logo_secondary': fields.binary("Logo Secondary"),
  56. 'image_medium': fields.function(
  57. _get_logo_secondary,
  58. fnct_inv=_set_logo_secondary,
  59. string="Medium-sized logo secondary",
  60. type="binary",
  61. multi="_get_logo_secondary",
  62. store={
  63. _inherit: (
  64. lambda self, cr, uid, ids, c={}:
  65. ids, ['logo_secondary'], 10
  66. ),
  67. }
  68. ),
  69. 'image_small': fields.function(
  70. _get_logo_secondary,
  71. fnct_inv=_set_logo_secondary,
  72. string="Small-sized logo secondary",
  73. type="binary",
  74. multi="_get_logo_secondary",
  75. store={
  76. _inherit: (
  77. lambda self, cr, uid, ids, c={}:
  78. ids, ['image'], 10),
  79. },
  80. ),
  81. 'has_logo_secondary': fields.function(
  82. _has_logo_secondary, type="boolean"
  83. ),
  84. 'smart_logo': fields.function(
  85. _get_smart_logo,
  86. string="Logo",
  87. type="binary"
  88. )
  89. }