# -*- coding: utf-8 -*- # Copyright 2024-2026 Nexa Systems Inc. # License OPL-1 (Odoo Proprietary License v1.0) from odoo import models class LoanerEmailMixin(models.AbstractModel): _name = 'fusion.loaner.email.mixin' _description = 'Loaner Email Builder Mixin' _EMAIL_COLORS = { 'info': '#2B6CB0', 'success': '#38a169', 'attention': '#d69e2e', 'urgent': '#c53030', } def _email_build( self, title, summary, sections=None, note=None, note_color=None, email_type='info', attachments_note=None, button_url=None, button_text='View Details', sender_name=None, extra_html='', ): accent = self._EMAIL_COLORS.get(email_type, self._EMAIL_COLORS['info']) company = self._get_company_info() parts = [] parts.append( f'
' f'
' f'
' ) parts.append( f'

{company["name"]}

' ) parts.append( f'

{title}

' ) parts.append( f'

{summary}

' ) if sections: for heading, rows in sections: parts.append(self._email_section(heading, rows)) if note: nc = note_color or accent parts.append(self._email_note(note, nc)) if extra_html: parts.append(extra_html) if attachments_note: parts.append(self._email_attachment_note(attachments_note)) if button_url: parts.append(self._email_button(button_url, button_text, accent)) signer = sender_name or (self.env.user.name if self.env.user else '') parts.append( f'

' f'Best regards,
' f'{signer}
' f'{company["name"]}

' ) parts.append('
') footer_parts = [company['name']] if company['phone']: footer_parts.append(company['phone']) if company['email']: footer_parts.append(company['email']) footer_text = ' · '.join(footer_parts) parts.append( f'
' f'

' f'{footer_text}
' f'This is an automated notification from the Loaner Management System.

' f'
' ) parts.append('
') return ''.join(parts) def _email_section(self, heading, rows): if not rows: return '' html = ( '' f'' ) for label, value in rows: if value is None or value == '' or value is False: continue html += ( f'' f'' f'' f'' ) html += '
{heading}
{label}{value}
' return html def _email_note(self, text, color='#2B6CB0'): return ( f'
' f'

{text}

' f'
' ) def _email_button(self, url, text='View Details', color='#2B6CB0'): return ( f'

' f'{text}

' ) def _email_attachment_note(self, description): return ( f'
' f'

' f'Attached: {description}

' f'
' ) def _email_status_badge(self, label, color='#2B6CB0'): bg_map = { '#38a169': 'rgba(56,161,105,0.12)', '#2B6CB0': 'rgba(43,108,176,0.12)', '#d69e2e': 'rgba(214,158,46,0.12)', '#c53030': 'rgba(197,48,48,0.12)', } bg = bg_map.get(color, 'rgba(43,108,176,0.12)') return ( f'' f'{label}' ) def _get_company_info(self): company = getattr(self, 'company_id', None) or self.env.company return { 'name': company.name or 'Our Company', 'phone': company.phone or '', 'email': company.email or '', } def _email_is_enabled(self): ICP = self.env['ir.config_parameter'].sudo() val = ICP.get_param('fusion_loaners.enable_email_notifications', 'True') return val.lower() in ('true', '1', 'yes')