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.

57 lines
2.2 KiB

  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Web Easy Switch Company module for OpenERP
  5. # Copyright (C) 2014 GRAP (http://www.grap.coop)
  6. # @author Sylvain LE GAL (https://twitter.com/legalsylvain)
  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 fields
  23. from openerp.osv.orm import Model
  24. from openerp.tools import image_resize_image
  25. class res_company(Model):
  26. _inherit = 'res.company'
  27. # Custom Section
  28. def _switch_company_get_companies_from_partner(
  29. self, cr, uid, ids, context=None):
  30. return self.pool['res.company'].search(
  31. cr, uid, [('partner_id', 'in', ids)], context=context)
  32. # Fields function Section
  33. def _get_logo_topbar(self, cr, uid, ids, _field_name, _args, context=None):
  34. result = dict.fromkeys(ids, False)
  35. for record in self.browse(cr, uid, ids, context=context):
  36. size = (48, 48)
  37. result[record.id] = image_resize_image(
  38. record.partner_id.image, size)
  39. return result
  40. # Columns Section
  41. _columns = {
  42. 'logo_topbar': fields.function(
  43. _get_logo_topbar,
  44. string="Logo displayed in the switch company menu",
  45. type="binary", store={
  46. 'res.company': (lambda s, c, u, i, x: i, ['partner_id'], 10),
  47. 'res.partner': (_switch_company_get_companies_from_partner,
  48. ['image'], 10),
  49. }
  50. ),
  51. }