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.

46 lines
1.6 KiB

  1. /* Copyright 2019 Druidoo - Iván Todorovich
  2. License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). */
  3. odoo.define('pos_invoice_send_mail.models', function (require) {
  4. "use strict";
  5. var models = require('point_of_sale.models');
  6. var PosModelSuper = models.PosModel.prototype;
  7. models.PosModel = models.PosModel.extend({
  8. push_and_invoice_order: function(order) {
  9. var client = order.get_client()
  10. if (order.is_to_send_mail() && client && !client.email) {
  11. var res = new $.Deferred();
  12. res.reject({code:400, message:'Missing Customer Email', data:{}});
  13. return res;
  14. }
  15. return PosModelSuper.push_and_invoice_order.apply(this, arguments);
  16. },
  17. });
  18. var OrderSuper = models.Order.prototype;
  19. models.Order = models.Order.extend({
  20. initialize: function(attributes, options) {
  21. OrderSuper.initialize.apply(this, arguments);
  22. this.to_send_mail = false;
  23. },
  24. set_to_send_mail: function(to_send_mail) {
  25. this.assert_editable();
  26. this.to_send_mail = to_send_mail;
  27. },
  28. is_to_send_mail: function() {
  29. return this.to_send_mail;
  30. },
  31. // We export to JSON so we can send this to the backend
  32. // without having to reimplement push_and_invoice_order
  33. export_as_JSON: function () {
  34. var res = OrderSuper.export_as_JSON.apply(this, arguments);
  35. res.to_send_mail = this.to_send_mail;
  36. return res;
  37. },
  38. });
  39. });