def get_default_summary(self, options):
     res = super(AccountFollowUpReport, self).get_default_summary(options)
     followup_line = self.get_followup_line(options)
     partner = self.env['res.partner'].browse(options.get('partner_id'))
     lang = partner.lang or self.env.user.lang or 'en_US'
     summary_bottom = ''
     subject = 'Account Customer Statement'
     if followup_line:
         summary_bottom = followup_line.with_context(
             lang=lang).description_bottom or ''
         signature = followup_line.with_context(
             lang=lang).signature or 'Accounting Team'
         subject = followup_line.with_context(lang=lang).subject
         try:
             summary_bottom = summary_bottom % {
                 'partner_name': partner.name,
                 'date': time.strftime('%Y-%m-%d'),
                 'user_signature': html2plaintext(self.env.user.signature
                                                  or ''),
                 'company_name': self.env.user.company_id.name
             }
         except ValueError as e:
             message = "An error has occurred while formatting your followup letter/email (bottom). (Lang: %s, Followup Level: #%s) \n\nFull error description: %s" \
                       % (partner.lang, followup_line.id, e)
             raise ValueError(message)
     else:
         summary_bottom =  self.env.user.company_id.with_context(lang=lang).overdue_msg or \
                self.env['res.company'].with_context(lang=lang).default_get(['overdue_msg'])['overdue_msg']
         signature = 'Accounting Team'
     options['summary_bottom'] = summary_bottom
     options['signature'] = signature
     options['subject'] = subject
     return res
Example #2
0
    def write(self, vals):
        """
        Copy content from website_description to index_content
        so that the content can be used for searching.

        :param vals: dict, changed values
        :return: super
        """
        if vals.get("website_description"):
            vals["index_content"] = html2plaintext(vals.get("website_description"))
        return super(Slide, self).write(vals)
Example #3
0
 def _compute_color(self):
     for row in self:
         if len(html2plaintext(row.body).strip()) < 15 \
                 and row.direction == 'out':
             # mass mailing
             row.color = 'gray'
         elif row.direction == 'in':
             row.color = 'red'
         else:
             # outgoing
             row.color = 'green'
Example #4
0
 def _compute_color(self):
     for row in self:
         if len(html2plaintext(
                 row.body).strip()) < 15 and row.direction == "out":
             # mass mailing
             row.color = "gray"
         elif row.direction == "in":
             row.color = "red"
         else:
             # outgoing
             row.color = "green"
Example #5
0
 def _prepare_message_new_custom_values(self, msg, custom_values=None):
     if custom_values is None:
         custom_values = {}
     desc = html2plaintext(msg.get('body')) if msg.get('body') else ''
     defaults = {
         'name': msg.get('subject') or _("No Subject"),
         'description': desc,
         'email_from': msg.get('from'),
         'email_cc': msg.get('cc'),
         'user_id': False,
         'partner_id': msg.get('author_id', False),
     }
     defaults.update(custom_values)
     return defaults, msg
    def print_followup(self, options, params):
        partner_id = params.get('partner')
        if partner_id:
            partner = self.env['res.partner'].browse(partner_id)
            partner.message_post(
                body=_('Follow-up letter printed'),
                subtype='account_reports.followup_logged_action',
                message_type="notification")
        options['partner_id'] = str(partner_id)
        followup_line = self.get_followup_line(options)
        options['partner_id'] = partner_id
        subject = 'Account Customer Statement'
        if followup_line:
            lang = partner.lang or self.env.user.lang or 'en_US'
            summary_bottom = followup_line.with_context(
                lang=lang).description_bottom or ''
            signature = followup_line.with_context(
                lang=lang).signature or 'Accounting Team'
            subject = followup_line.with_context(lang=lang).subject
            try:
                summary_bottom = summary_bottom % {
                    'partner_name': partner.name,
                    'date': time.strftime('%Y-%m-%d'),
                    'user_signature': html2plaintext(self.env.user.signature
                                                     or ''),
                    'company_name': self.env.user.company_id.name
                }
            except ValueError as e:
                message = "An error has occurred while formatting your followup letter/email (bottom). (Lang: %s, Followup Level: #%s) \n\nFull error description: %s" \
                          % (partner.lang, followup_line.id, e)
                raise ValueError(message)

            options['summary_bottom'] = summary_bottom
            options['signature'] = signature
            options['subject'] = subject
        return {
            'type': 'ir_actions_account_report_download',
            'data': {
                'model': 'account.followup.report',
                'options': json.dumps(options),
                'output_format': 'pdf',
            }
        }
 def _get_default_summary(self, options):
     followup_line = self.get_followup_line(options)
     partner = self.env['res.partner'].browse(options.get('partner_id'))
     lang = partner.lang or self.env.user.lang or 'en_US'
     if followup_line:
         partner = self.env['res.partner'].browse(options['partner_id'])
         lang = partner.lang or self.env.user.lang or 'en_US'
         summary = followup_line.with_context(lang=lang).description
         try:
             summary = summary % {
                 'partner_name': partner.name,
                 'date': time.strftime(DEFAULT_SERVER_DATE_FORMAT),
                 'user_signature': html2plaintext(self.env.user.signature
                                                  or ''),
                 'company_name': self.env.user.company_id.name
             }
         except ValueError as exception:
             message = "An error has occurred while formatting your followup letter/email. (Lang: %s, Followup Level: #%s) \n\nFull error description: %s" \
                       % (partner.lang, followup_line.id, exception)
             raise ValueError(message)
         return summary
     return super(AccountFollowupReport, self)._get_default_summary(options)
Example #8
0
def post_init_hook(cr, _):
    """ Initialize index_content based on website_description """
    env = api.Environment(cr, SUPERUSER_ID, {})
    slides = env["slide.slide"].search([])
    for slide in slides:
        slide.index_content = html2plaintext(slide.website_description)
    def send_email(self, options):
        if options and "partner_id" in options:
            partner_id = self.env['res.partner'].browse(
                options.get('partner_id'))
            email = self.env['res.partner'].browse(
                partner_id.address_get(['invoice'])['invoice']).email
            if email and email.strip():
                # Get report lines, containing invoice number
                lines = self.env['account.followup.report'].with_context(
                    lang=partner_id.lang, public=True).get_lines(options)
                invoice_ids = self.env['account.invoice']
                for line in lines:
                    if 'has_invoice' in line and line['has_invoice']:
                        aml = self.env['account.move.line'].browse(line['id'])
                        if aml and aml.invoice_id:
                            invoice_ids |= aml.invoice_id

                #Get all invoices related to numbers then browse it.
                for invoice in invoice_ids:
                    # Create ir.attachment and PDF for invoice when it doesn't exists
                    pdf = self.env.ref(
                        'account.account_invoices').sudo().render_qweb_pdf(
                            [invoice.id])[0]
                attachments = self.env['ir.attachment'].search([
                    ('res_id', 'in', invoice_ids.ids),
                    ('res_model', '=', "account.invoice")
                ]).ids

                subject = 'Account Customer Statement'
                followup_line = False
                if options and 'partner_followup_level' in options and options.get(
                        'partner_followup_level') and options.get(
                            'partner_followup_level')[str(partner_id.id)]:
                    followup_line = options.get('partner_followup_level')[str(
                        partner_id.id)][0]
                    if followup_line:
                        followup_line = self.env[
                            'account_followup.followup.line'].browse(
                                followup_line)
                        lang = partner_id.lang or self.env.user.lang or 'en_US'
                        summary_bottom = followup_line.with_context(
                            lang=lang).description_bottom or ''
                        signature = followup_line.with_context(
                            lang=lang).signature or 'Accounting Team'
                        subject = followup_line.with_context(lang=lang).subject
                        try:
                            summary_bottom = summary_bottom % {
                                'partner_name':
                                partner_id.name,
                                'date':
                                time.strftime('%Y-%m-%d'),
                                'user_signature':
                                html2plaintext(self.env.user.signature or ''),
                                'company_name':
                                self.env.user.company_id.name
                            }
                        except ValueError as e:
                            message = "An error has occurred while formatting your followup letter/email (bottom). (Lang: %s, Followup Level: #%s) \n\nFull error description: %s" \
                                      % (partner_id.lang, followup_line.id, e)
                            raise ValueError(message)

                        options['summary_bottom'] = summary_bottom
                        options['signature'] = signature
                        options['subject'] = subject

                body = self.with_context(print_mode=True,
                                         mail=True,
                                         keep_summary=True).get_html(options)
                # Attach to all related PDF to email
                mail = self.env['mail.mail'].create({
                    'subject':
                    _('%s - Payment Reminder') %
                    self.env.user.company_id.name if not followup_line
                    or not followup_line.subject else followup_line.subject,
                    'body_html':
                    body,
                    'email_from':
                    self.env.user.email or '',
                    'email_to':
                    email,
                    'attachment_ids': [(6, 0, attachments)]
                })
                msg = _(': Sent a followup email to %s\n%s' %
                        (email, body.decode('utf-8')))
                partner_id.message_post(
                    body=msg,
                    subtype='account_reports.followup_logged_action',
                    message_type="notification")
                return True
            else:
                raise exceptions.Warning(
                    _('Could not send mail to partner because it does not have any email address defined'
                      ))
        return False
Example #10
0
             line-height: inherit  ;">Message sent from </div>[email protected]
        </p>
    </body>
</html>
'''

mail.html_sanitize(html, strip_style=True)
#
#
#         <p>
#             <span>
#                 Тут Марис пишет очередной шаблон письма для Лаймонаса
#                  <a href="https://icode.by/" target="_blank">ICode.by</a>
#                     <div>Message sent from </div>[email protected]
#         </span></p>


text = 'Here Maris writes another template for Laimonas with a link to https://icode.by/'

mail.plaintext2html(text)
# <p>Here Maris writes another template for Laimonas with a link to <a href="https://icode.by/" target="_blank">https://icode.by/</a></p>

mail.html2plaintext(html)
# Тут Марис пишет очередной шаблон письма для Лаймонаса
# ICode.by [1]
# Message sent from [email protected]
#
#
#
# [1] https://icode.by/