Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

Hi,

I'm trying to send email as notification to some users when an employee creates new journal entry,

So this is my work :

account_move :

class AccountMove(models.Model):
    _inherit = "account.move"
    @api.multi
    def write(self,values):       
        journal_write = super(AccountMove,self).write(values)
        template_obj = self.env.ref('create_journal_control.email_template_notify_new_journal')
        body = template_obj.body_html
        mail_values = []
        if template_obj:
            mail_values = {
                'subject': template_obj.subject,
                'body_html': body,
                'email_to': template_obj.email_to, #';'.join(map(lambda x: x, receipt_list)),
                'email_cc': template_obj.email_cc, #';'.join(map(lambda x: x, email_cc)),
                'email_from': template_obj.email_from,
            }
        create_and_send_email = self.env['mail.mail'].create(mail_values).send()
        return journal_write

notify_new_journal.xml :

<record id="email_template_notify_new_journal" model="mail.template">
            <field name="name">Notify Create New Journal Entry</field>
            <field name="email_from">noreply@eureka</field>
            <field name="subject">Mayar - New journal entry created !</field>
            <field name="email_to">akaderb@gmail.com</field>
            <field name="email_cc">abdelkader.boukhelf@eureka.me</field>
            <field name="model_id" ref="account.model_account_move_line"/>          
            <field name="body_html">
                <![CDATA[
                    <p><strong>Dear Admins</strong></p>

                    <p>New journal entry has been created by --creator-- on --date--</p>

                    % if object.line_ids:
                        <ol>
                            % for line in object.line_ids
                                <li>${line.partner_id.name}</li>
                            % endfor
                        </ol>
                    % endif
                    <p>Journal created : --journal-- for Partner : --partner--</p>
                ]]>
            </field>
        </record>


But, the template doesn't render as expected, this is the mail :

Dear Admins

New journal entry has been created by --creator-- on --date--

% if object.line_ids:
    % for line in object.line_ids
  1. ${line.partner_id.name} % endfor
% endif

Journal created : --journal-- for Partner : --partner--


And also, I receive tow mails instead of one !

Please help me and thnaks !

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
0
Feb 21
4030
0
Okt 16
5778
1
Nov 17
8489
2
Okt 17
4364
2
Okt 17
6352