콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다

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 !

아바타
취소
관련 게시물 답글 화면 활동
0
2월 21
4096
0
10월 16
5838
1
11월 17
8591
2
10월 17
4422
2
10월 17
6414