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.

96 lines
3.4 KiB

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