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.

37 lines
1.3 KiB

  1. from dateutil.relativedelta import relativedelta
  2. from odoo import api, fields, models
  3. class ResPartnerIdNumber(models.Model):
  4. _name = "res.partner.id_number"
  5. _inherit = ["res.partner.id_number", "mail.thread", "mail.activity.mixin"]
  6. notification_date = fields.Date(string="Notification Date")
  7. @api.model
  8. def send_notification(self):
  9. today = fields.date.today()
  10. rec_ids = self.search(
  11. [
  12. ("category_id.send_notification", "=", True),
  13. ("category_id.days_before_expire", ">", 0),
  14. ("status", "in", ["open", "pending"]),
  15. ]
  16. )
  17. for rec in rec_ids:
  18. days_before_expire = rec.category_id.days_before_expire
  19. date_from = today - relativedelta(days=days_before_expire)
  20. if (
  21. rec.valid_until
  22. and days_before_expire
  23. and rec.valid_until >= date_from
  24. and rec.valid_until <= today
  25. and rec.category_id.email_template_id
  26. and not rec.notification_date
  27. ):
  28. rec.notification_date = today
  29. rec.category_id.email_template_id.send_mail(
  30. rec.id,
  31. force_send=True,
  32. )