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.

30 lines
1.0 KiB

  1. # Copyright 2019 Druidoo - Iván Todorovich
  2. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
  3. from odoo import api, models
  4. class PosOrder(models.Model):
  5. _inherit = 'pos.order'
  6. @api.model
  7. def create_from_ui(self, orders):
  8. """ Inherit method to send by email """
  9. order_ids = super().create_from_ui(orders)
  10. refs_to_send_mail = [
  11. o['data']['name'] for o in orders
  12. if o['data'].get('to_send_mail')
  13. ]
  14. # Identify orders to send email
  15. for order in self.browse(order_ids):
  16. if (
  17. order.config_id.iface_invoice_mail
  18. and order.invoice_id
  19. and not order.invoice_id.sent
  20. and order.pos_reference in refs_to_send_mail
  21. ):
  22. invoice_id = order.invoice_id.with_context(
  23. mark_invoice_as_sent=True)
  24. invoice_id.message_post_with_template(
  25. order.config_id.invoice_mail_template_id.id)
  26. return order_ids