Update rent_payment.py
This commit is contained in:
parent
74c7e6b50d
commit
c1f25ebeb3
|
|
@ -200,6 +200,72 @@ class RentPayment(models.Model):
|
|||
record.write({"state": 'due'})
|
||||
else:
|
||||
raise exceptions.ValidationError(_("You Must Confirm Contract First"))
|
||||
def _check_due_payments(self):
|
||||
payments = self.search([('state', '=', 'draft'), ('due_date', '<=', fields.Date.today())])
|
||||
for payment in payments:
|
||||
if payment.contract_id.state == 'confirm':
|
||||
payment.write({'state': 'due'})
|
||||
if payment.code == '/' or not payment.code:
|
||||
code = self.env['ir.sequence'].next_by_code('rent.payment') or '/'
|
||||
payment.write({'code': code})
|
||||
def _send_payment_notifications(self):
|
||||
today = fields.Date.today()
|
||||
next_week = today + timedelta(days=7)
|
||||
|
||||
payments_today = self.search([('due_date', '=', today), ('state', '=', 'draft')])
|
||||
payments_next_week = self.search([('due_date', '=', next_week), ('state', '=', 'draft')])
|
||||
|
||||
template_today = self.env.ref('property_management.email_template_due_today')
|
||||
template_next_week = self.env.ref('property_management.email_template_due_next_week')
|
||||
date_deadline = fields.Date.today()
|
||||
note = _("Please Chech the Due Date in rent")
|
||||
summary = _("Due Date Rent")
|
||||
|
||||
for payment in payments_today:
|
||||
email_list = [payment.renter_id.email,payment.user_id.email]
|
||||
email_to = ','.join(email_list)
|
||||
payment.message_post_with_template(template_today.id)
|
||||
if template_today:
|
||||
template_today.send_mail(payment.id, force_send=True,raise_exception=True,email_values={'email_to': email_to})
|
||||
payment.sudo().activity_schedule(
|
||||
'mail.mail_activity_data_todo', date_deadline,
|
||||
note=note,
|
||||
user_id=payment.user_id.id,
|
||||
res_id=payment.id,
|
||||
summary=summary
|
||||
)
|
||||
payment.sudo().activity_schedule(
|
||||
'mail.mail_activity_data_todo', date_deadline,
|
||||
note=note,
|
||||
user_id=payment.partner_id.user_id.id,
|
||||
res_id=payment.id,
|
||||
summary=summary
|
||||
)
|
||||
# إرسال إشعار إلى المستأجر والمستخدمين
|
||||
# يمكنك استخدام notification module للإشعارات أو mail.activity
|
||||
|
||||
for payment in payments_next_week:
|
||||
email_list = [payment.renter_id.email,payment.user_id.email]
|
||||
email_to = ','.join(email_list)
|
||||
payment.message_post_with_template(template_next_week.id)
|
||||
if template_next_week:
|
||||
template_next_week.send_mail(payment.id, force_send=True,raise_exception=True,email_values={'email_to':email_to})
|
||||
payment.sudo().activity_schedule(
|
||||
'mail.mail_activity_data_todo', date_deadline,
|
||||
note=note,
|
||||
user_id=payment.user_id.id,
|
||||
res_id=payment.id,
|
||||
summary=summary
|
||||
)
|
||||
payment.sudo().activity_schedule(
|
||||
'mail.mail_activity_data_todo', date_deadline,
|
||||
note=note,
|
||||
user_id=payment.partner_id.user_id.id,
|
||||
res_id=payment.id,
|
||||
summary=summary
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
def action_validate(self):
|
||||
for record in self:
|
||||
|
|
|
|||
Loading…
Reference in New Issue