diff --git a/odex25_realstate/property_management/data/ir_sequence_data.xml b/odex25_realstate/property_management/data/ir_sequence_data.xml index 4744ce765..657d14ea5 100644 --- a/odex25_realstate/property_management/data/ir_sequence_data.xml +++ b/odex25_realstate/property_management/data/ir_sequence_data.xml @@ -1,6 +1,59 @@ + + + Payment Due Today + + Payment Due Today + ${(user.email)|safe} + + Dear ${object.renter_id.name},

+

This is a reminder that your payment is due today for the rental contract ${object.contract_id.name}.

+

Thank you.

+ ]]> +
+
+ + + + Payment Due Next Week + + Payment Due Next Week + ${(user.email)|safe} + + + Dear ${object.renter_id.name},

+

This is a reminder that your payment is due next week for the rental contract ${object.contract_id.name}.

+

Thank you.

+ ]]> +
+
+ + + + Check Due Payments + + code + model._check_due_payments() + 1 + minutes + -1 + + + + Send Payment Notifications + + code + model._send_payment_notifications() + 1 + days + -1 + + Rental Contract rental.contract diff --git a/odex25_realstate/property_management/models/rent_payment.py b/odex25_realstate/property_management/models/rent_payment.py index 44874dfc7..9c96f761a 100644 --- a/odex25_realstate/property_management/models/rent_payment.py +++ b/odex25_realstate/property_management/models/rent_payment.py @@ -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: