Odoo Help

0

2
2 Answers
2
Ankit Gauri
18/04/17, 01:46

Hello 

you have added chatter it just creates a log but for sending an email you have write method also you have create email template as well.

below is the code which i have write to send an email when picking validates/done with template design you can create your own template design

@api.multi 

def make_pickings_auto_done(self):

        emails = []

        email_to = ''

        mail_mail = self.env['mail.mail']

        for pick in self:

            partner_ids = pick.message_follower_ids and \

                          pick.message_follower_ids.ids or []

            for partner in self.env['mail.followers'].browse(partner_ids):

                emails.append(partner.partner_id.email)

            product_dic = {}

            for picking_line in pick.pack_operation_product_ids:

                product_dic.update({str(picking_line.product_id.name) :

                                        picking_line.qty_done})

        for email in emails:

            email_to = email_to and email_to + ',' + email or email_to + email

        do = pick.name and pick.name or ""

        body_html = '''

                            <div>

                               <p>

                        Hello,

                        <br/><br/>

                            Delivery order ''' + do + ''' is move to done

                            state.

                            <br/><br/>

                            The details of shipping is as below.

                            <br/><br/>

                        </p>

                        <table border="1" cellpadding="5" cellspacing="1">

                        <tbody>

                            <tr>

                                <th>Delivery Order</th>

                                <th>Customer</th>

                                <th>Product</th>

                                <th>Qty</th>

                            </tr>'''

        for nm,qty in product_dic.iteritems():

            body_html += '''<tr>

                                <td>''' + do + '''</td>

                                <td>''' + pick.partner_id.name + '''</td>

                                <td>''' + nm + '''</td>

                                <td>''' + str(qty) +'''</td>

                            </tr>'''

        body_html += '''</tbody>

                        </table>'''

        mail_values = {

            'email_from': self.company_id.partner_id.email or

                          'noreply@localhost',

            'email_to': email_to,

            'subject': 'Delivery order ',

            'body_html': body_html,

            'state': 'outgoing',

            'message_type': 'email',

        }

        mail_id = mail_mail.create(mail_values)

        if mail_id:

            for mail in mail_id:

                # To avoid sending mail/notification multiple times

                return mail.send()

        else:

            return True


0
Sehrish
18/02/18, 23:02

Yes you can send email on the change of fields in odoo. I have a code that sends email on button click you can modify the method of button click to onchange method and that it. To get complete code and description read: http://learnopenerp.blogspot.com/2017/08/odoo-how-to-send-email-on-button-click.html

1 Comment
Sehrish
18/02/18, 23:03

Odoo how to send email on button click

just copy the method of sending email and use it in onchange method.

http://learnopenerp.blogspot.com/2017/08/odoo-how-to-send-email-on-button-click.html

Thanks

Ask a Question
Keep Informed
3 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register