pos.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # OpenERP, Open Source Management Solution
  5. # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. import logging
  22. import time
  23. from openerp import tools
  24. from openerp.osv import fields, osv
  25. from openerp.tools.translate import _
  26. import openerp.addons.decimal_precision as dp
  27. import openerp.addons.product.product
  28. import base64
  29. _logger = logging.getLogger(__name__)
  30. class pos_config(osv.osv):
  31. _inherit = 'pos.config'
  32. def _get_image(self, cr, uid, ids, name, args, context=None):
  33. result = dict.fromkeys(ids, False)
  34. for obj in self.browse(cr, uid, ids, context=context):
  35. result[obj.id] = tools.image_get_resized_images(obj.image)
  36. return result
  37. def _set_image(self, cr, uid, id, name, value, args, context=None):
  38. return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)
  39. def _get_default_image(self, cr, uid, context=None):
  40. image_path = openerp.modules.get_module_resource('pos_logo', 'static/src/img', 'default.png')
  41. return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
  42. _columns = {
  43. 'image': fields.binary("Logo",
  44. help="This field holds the image, limited to 1024x1024px."),
  45. 'image_medium': fields.function(_get_image, fnct_inv=_set_image,
  46. string="Medium-sized photo", type="binary", multi="_get_image",
  47. store = {
  48. 'pos.config': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
  49. },
  50. help="Medium-sized photo of the student. It is automatically "\
  51. "resized as a 128x128px image, with aspect ratio preserved. "\
  52. "Use this field in form views or some kanban views."),
  53. 'image_small': fields.function(_get_image, fnct_inv=_set_image,
  54. string="Small-sized photo", type="binary", multi="_get_image",
  55. store = {
  56. 'pos.config': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
  57. },
  58. help="Small-sized photo of the employee. It is automatically "\
  59. "resized as a 64x64px image, with aspect ratio preserved. "\
  60. "Use this field anywhere a small image is required."),
  61. 'time_format':fields.selection([('12','12 Hour Format'),('24','24 Hour Format')],'Time Format'),
  62. }
  63. _defaults={
  64. 'image_medium':_get_default_image,
  65. 'time_format':'24',
  66. }