This commit is contained in:
gsinghpal
2026-03-01 14:42:49 -05:00
parent b925766966
commit a3e85a23ef
28 changed files with 2283 additions and 195 deletions

View File

@@ -8,7 +8,8 @@
<field name="name">Rental: Renewal Reminder</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Rental {{ object.name }} Renews Soon</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -40,7 +41,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -50,7 +51,8 @@
<field name="name">Rental: Renewal Confirmation</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Rental {{ object.name }} Renewed</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -80,7 +82,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -90,7 +92,8 @@
<field name="name">Rental: Payment Receipt</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Payment Receipt {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -119,7 +122,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -129,7 +132,8 @@
<field name="name">Rental: Cancellation Confirmed</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Cancellation Received {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -152,7 +156,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -162,7 +166,8 @@
<field name="name">Rental: Agreement for Signing</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Rental Agreement {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -194,7 +199,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -204,7 +209,8 @@
<field name="name">Rental: Signed Agreement Copy</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Your Signed Rental Agreement {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -235,7 +241,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -245,7 +251,8 @@
<field name="name">Rental: Purchase Conversion Offer</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Make Your Rental Yours {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -278,7 +285,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -288,7 +295,8 @@
<field name="name">Rental: Security Deposit Refund Initiated</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Security Deposit Refund Processing {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -318,7 +326,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -328,7 +336,8 @@
<field name="name">Rental: Security Deposit Refund Complete</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Security Deposit Refunded {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -359,7 +368,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -369,7 +378,8 @@
<field name="name">Rental: Invoice + Payment Receipt</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Invoice &amp; Payment Confirmation {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -412,7 +422,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -422,7 +432,8 @@
<field name="name">Rental: Damage Notification</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Rental Inspection Update {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -450,7 +461,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -460,7 +471,8 @@
<field name="name">Rental: Thank You + Review</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Thank You {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -493,7 +505,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -503,7 +515,8 @@
<field name="name">Rental: Card Reauthorization Request</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Update Payment Card {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -529,7 +542,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->
@@ -539,7 +552,8 @@
<field name="name">Rental: Card Updated Confirmation</field>
<field name="model_id" ref="sale.model_sale_order"/>
<field name="subject">{{ object.company_id.name }} - Payment Card Updated {{ object.name }}</field>
<field name="email_from">{{ (object.user_id.email_formatted or object.company_id.email_formatted or user.email_formatted) }}</field>
<field name="email_from">{{ (object.company_id.email_formatted or object.user_id.email_formatted or user.email_formatted) }}</field>
<field name="use_default_to" eval="False"/>
<field name="partner_to">{{ object.partner_id.id }}</field>
<field name="body_html" type="html">
<div style="font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Arial,sans-serif;max-width:600px;margin:0 auto;color:#2d3748;">
@@ -568,7 +582,7 @@
</div>
</field>
<field name="lang">{{ object.partner_id.lang }}</field>
<field name="auto_delete" eval="True"/>
<field name="auto_delete" eval="False"/>
</record>
<!-- ============================================================ -->

View File

@@ -623,6 +623,7 @@ class SaleOrder(models.Model):
raise_if_not_found=False,
)
if not template:
_logger.error("Renewal confirmation template not found for %s", self.name)
return
attachment_ids = []
@@ -635,14 +636,18 @@ class SaleOrder(models.Model):
invoice, 'Renewal',
)
template.with_context(
payment_ok=payment_ok,
renewal_log=renewal_log,
).send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
try:
template.with_context(
payment_ok=payment_ok,
renewal_log=renewal_log,
).send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
_logger.warning("Renewal confirmation email sent for %s", self.name)
except Exception as e:
_logger.error("Failed to send renewal confirmation email for %s: %s", self.name, e)
def _send_payment_receipt_email(self, invoice, transaction):
"""Send payment receipt email after successful collection."""
@@ -912,7 +917,13 @@ class SaleOrder(models.Model):
raise_if_not_found=False,
)
if template:
template.send_mail(self.id, force_send=True)
try:
template.send_mail(self.id, force_send=True)
_logger.warning("Rental agreement email sent for %s", self.name)
except Exception as e:
_logger.error("Failed to send agreement email for %s: %s", self.name, e)
else:
_logger.error("Agreement email template not found for %s", self.name)
self.message_post(body=_("Rental agreement sent to customer for signing."))
def action_send_card_reauthorization(self):
@@ -1308,6 +1319,7 @@ class SaleOrder(models.Model):
raise_if_not_found=False,
)
if not template:
_logger.error("Deposit refund initiated template not found for %s", self.name)
return
attachment_ids = []
@@ -1317,11 +1329,15 @@ class SaleOrder(models.Model):
credit_note, 'Deposit Credit Note',
)
template.send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
try:
template.send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
_logger.warning("Deposit refund initiated email sent for %s", self.name)
except Exception as e:
_logger.error("Failed to send deposit refund initiated email for %s: %s", self.name, e)
def _send_deposit_refund_email(self):
"""Send the security deposit refund completion email with credit note and receipt."""
@@ -1331,6 +1347,7 @@ class SaleOrder(models.Model):
raise_if_not_found=False,
)
if not template:
_logger.error("Deposit refund template not found for %s", self.name)
return
attachment_ids = []
@@ -1342,11 +1359,15 @@ class SaleOrder(models.Model):
receipt_ids = self._find_poynt_receipt_attachments(credit_note)
attachment_ids.extend(receipt_ids)
template.send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
try:
template.send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
_logger.warning("Deposit refund email sent for %s", self.name)
except Exception as e:
_logger.error("Failed to send deposit refund email for %s: %s", self.name, e)
def _send_invoice_with_receipt(self, invoice, invoice_type=''):
"""Send invoice email with the invoice PDF and payment receipt attached.
@@ -1361,6 +1382,7 @@ class SaleOrder(models.Model):
raise_if_not_found=False,
)
if not template:
_logger.error("Invoice receipt email template not found for %s", self.name)
return
type_label = {
@@ -1374,14 +1396,24 @@ class SaleOrder(models.Model):
receipt_ids = self._find_poynt_receipt_attachments(invoice)
attachment_ids.extend(receipt_ids)
template.with_context(
rental_invoice=invoice,
rental_invoice_type=invoice_type,
).send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
try:
template.with_context(
rental_invoice=invoice,
rental_invoice_type=invoice_type,
).send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
_logger.warning(
"Invoice receipt email sent for %s (%s) with %d attachments",
self.name, type_label, len(attachment_ids),
)
except Exception as e:
_logger.error(
"Failed to send invoice receipt email for %s (%s): %s",
self.name, type_label, e,
)
# =================================================================
# Email Attachment Helpers
@@ -1605,11 +1637,17 @@ class SaleOrder(models.Model):
raise_if_not_found=False,
)
if template:
template.send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': [attachment.id]},
)
try:
template.send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': [attachment.id]},
)
_logger.warning("Signed agreement email sent for %s", self.name)
except Exception as e:
_logger.error("Failed to send signed agreement email for %s: %s", self.name, e)
else:
_logger.error("Signed agreement email template not found for %s", self.name)
def action_preview_rental_agreement(self):
"""Open the rental agreement PDF in a preview dialog."""
@@ -1702,14 +1740,19 @@ class SaleOrder(models.Model):
raise_if_not_found=False,
)
if not template:
_logger.error("Thank you email template not found for %s", self.name)
return
attachment_ids = self._generate_agreement_attachment_ids()
template.with_context(
google_review_url=self._get_google_review_url(),
).send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
try:
template.with_context(
google_review_url=self._get_google_review_url(),
).send_mail(
self.id,
force_send=True,
email_values={'attachment_ids': attachment_ids} if attachment_ids else {},
)
_logger.warning("Thank you email sent for %s", self.name)
except Exception as e:
_logger.error("Failed to send thank you email for %s: %s", self.name, e)