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.

49 lines
1.6 KiB

  1. /* License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
  2. odoo.define("pos_ticket_logo.models", function (require) {
  3. "use strict";
  4. var models = require("point_of_sale.models");
  5. var exports = {};
  6. var _pictures = _.findWhere(
  7. models.PosModel.prototype.models,
  8. {label: "pictures"}
  9. );
  10. _pictures.loaded = function (self) {
  11. self.company_logo = new Image();
  12. var logo_loaded = new $.Deferred();
  13. self.company_logo.onload = function () {
  14. var img = self.company_logo;
  15. var ratio = 1;
  16. var targetwidth = 260;
  17. var maxheight = 120;
  18. if (img.width !== targetwidth) {
  19. ratio = targetwidth / img.width;
  20. }
  21. if (img.height * ratio > maxheight) {
  22. ratio = maxheight / img.height;
  23. }
  24. var width = Math.floor(img.width * ratio);
  25. var height = Math.floor(img.height * ratio);
  26. var c = document.createElement('canvas');
  27. c.width = width;
  28. c.height = height;
  29. var ctx = c.getContext('2d');
  30. ctx.drawImage(self.company_logo, 0, 0, width, height);
  31. self.company_logo_base64 = c.toDataURL();
  32. logo_loaded.resolve();
  33. };
  34. self.company_logo.onerror = function () {
  35. logo_loaded.reject();
  36. };
  37. self.company_logo.crossOrigin = "anonymous";
  38. self.company_logo.src = '/web/binary/image?model=res.company&id=' +
  39. self.company.id + '&field=logo';
  40. return logo_loaded;
  41. };
  42. return exports;
  43. });