mirror of
https://gitlab.com/flectra-community/partner-contact.git
synced 2024-11-15 02:32:04 +00:00
38 lines
1.3 KiB
Python
38 lines
1.3 KiB
Python
|
from dateutil.relativedelta import relativedelta
|
||
|
|
||
|
from flectra import api, fields, models
|
||
|
|
||
|
|
||
|
class ResPartnerIdNumber(models.Model):
|
||
|
_name = "res.partner.id_number"
|
||
|
_inherit = ["res.partner.id_number", "mail.thread", "mail.activity.mixin"]
|
||
|
|
||
|
notification_date = fields.Date(string="Notification Date")
|
||
|
|
||
|
@api.model
|
||
|
def send_notification(self):
|
||
|
today = fields.date.today()
|
||
|
rec_ids = self.search(
|
||
|
[
|
||
|
("category_id.send_notification", "=", True),
|
||
|
("category_id.days_before_expire", ">", 0),
|
||
|
("status", "in", ["open", "pending"]),
|
||
|
]
|
||
|
)
|
||
|
for rec in rec_ids:
|
||
|
days_before_expire = rec.category_id.days_before_expire
|
||
|
date_from = today - relativedelta(days=days_before_expire)
|
||
|
if (
|
||
|
rec.valid_until
|
||
|
and days_before_expire
|
||
|
and rec.valid_until >= date_from
|
||
|
and rec.valid_until <= today
|
||
|
and rec.category_id.email_template_id
|
||
|
and not rec.notification_date
|
||
|
):
|
||
|
rec.notification_date = today
|
||
|
rec.category_id.email_template_id.send_mail(
|
||
|
rec.id,
|
||
|
force_send=True,
|
||
|
)
|