Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
7 Odpovědi
16384 Zobrazení

Hi guys, how can I do it ?

My template contains:


<openerp>

<data noupdate="1">

<record id="stock_check_form" model="email.template">

<field name="name">Order form</field>

<field name="email_from">odoo@rs.com</field>

<field name="subject">Order</field>

<field name="model_id" ref="stock.check"/>

<field name="email_to" >rob@com.com</field>

<field name="partner_to"></field>

<field name="auto_delete" eval="False"/>

<field name="body_html">

<![CDATA[

<style>

span.oe_mail_footer_access {

display:block;

text-align:center;

color:grey;

}

</style>

<div style="border-radius: 2px; max-width: 800px; height: auto;margin-left: auto;margin-right: auto;background-color:#f9f9f9;">

<div style="height: auto;margin-left:12px;margin-top:30px;">

<p>U R G E N T !</p>

</div>

</div>

]]>

</field>

</record>

</data>

</openerp>

If I put data directly into template it look  like

tags only even if data in html_body field are formatted like that:

== email >>>>>=========================

[(0, 0, {'eelms': 132.0, 'eeqty_required': 90.0, 'eeproduct_id': 3, 'eemail_id': 39, 'eeproduct_qty': 85.0, 'eecurrent_stock': 0, 'eemwosres': 14}), (0, 0, {'eelms': 8.0, 'eeqty_required': 5.0, 'eeproduct_id': 18, 'eemail_id': 39, 'eeproduct_qty': 6.0, 'eecurrent_stock': 1, 'eemwosres': 1}), (0, 0, {'eelms': 14.0, 'eeqty_required': 8.0, 'eeproduct_id': 300, 'eemail_id': 39, 'eeproduct_qty': 13.0, 'eecurrent_stock': 1, 'eemwosres': 2}), (0, 0, {'eelms': 42.0, 'eeqty_required': 30.0, 'eeproduct_id': 909, 'eemail_id': 39, 'eeproduct_qty': 25.0, 'eecurrent_stock': 3, 'eemwosres': 4}), (0, 0, {'eelms': 39.0, 'eeqty_required': 27.0, 'eeproduct_id': 1214, 'eemail_id': 39, 'eeproduct_qty': 24.0, 'eecurrent_stock': 1, 'eemwosres': 4})]

== body >>>>>>=================================

[<tr><td><b>0</b></td><td>0</td><td>{""eelms"":132.0""eeqty_required"":90.0""eeproduct_id"":3""eemail_id"":39""eeproduct_qty"":85.0""eecurrent_stock"":0""eemwosres"":14}</td></tr><tr><td><b>0</b></td><td>0</td><td>{""eelms"":8.0""eeqty_required"":5.0""eeproduct_id"":18""eemail_id"":39""eeproduct_qty"":6.0""eecurrent_stock"":1""eemwosres"":1}</td></tr><tr><td><b>0</b></td><td>0</td><td>{""eelms"":14.0""eeqty_required"":8.0""eeproduct_id"":300""eemail_id"":39""eeproduct_qty"":13.0""eecurrent_stock"":1""eemwosres"":2}</td></tr><tr><td><b>0</b></td><td>0</td><td>{""eelms"":42.0""eeqty_required"":30.0""eeproduct_id"":909""eemail_id"":39""eeproduct_qty"":25.0""eecurrent_stock"":3""eemwosres"":4}</td></tr><tr><td><b>0</b></td><td>0</td><td>{""eelms"":39.0""eeqty_required"":27.0""eeproduct_id"":1214""eemail_id"":39""eeproduct_qty"":24.0""eecurrent_stock"":1""eemwosres"":4}</td></tr>]

Don't know how to ..... ;(

Why I'm getting this:  [<tr><td><b>0</b></td><td>0</td><td>{""eelms"":132.0""eeqty_required"":90.0""eeproduct_id"":3""eemail_id"":39""eeproduct_qty"":85.0""eecurrent_stock"":0""eemwosres"":14}

instead of:

  [<tr><td><b>eelms:132.0 </b></td><td>eeqty_required:90.0 </td><td>.....]

or

  [<tr><td><b>132.0 </b></td><td>90.0 </td><td>.....]  

?

Avatar
Zrušit
Nejlepší odpověď

Hi Dr Obx,

Create a new XML file and add it to the __openerp__.py file as dependency. An example of such a template:

<openerp>
<data noupdate="1">
<record id="your_template_email" model="mail.template">
<field name="name">Template title</field>
<field name="email_from">${object.event_id.user_id.email or ''}</field>
<field name="subject">${object.event_id.name} - Reminder</field>
<field name="model_id" ref="calendar.model_calendar_attendee"/>
<field name="email_to" >${('' if object.partner_id and object.partner_id.email and object.partner_id.email==object.email else object.email|safe)}</field>
<field name="partner_to">${object.partner_id and object.partner_id.email and object.partner_id.email==object.email and object.partner_id.id or False }</field>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[
<style>
span.oe_mail_footer_access {
display:block;
text-align:center;
color:grey;
}
</style>
<div style="border-radius: 2px; max-width: 1200px; height: auto;margin-left: auto;margin-right: auto;background-color:#f9f9f9;">
<div style="height: auto;margin-left:12px;margin-top:30px;">
<p>ANY TEXT YOU WANT HERE!</p>
</div>
</div>
]]>
</field>
</record>
</data>
</openerp>


As you can see you can add CSS etc in it. An important note is to add data noupdate="1" in it though! So the template is never reloaded.

Yenthe

Avatar
Zrušit
Autor

Thank you Yanthe, If I can ask you one more question, how can I populate a table in email with data from the list I created ? For example: as a result of my mtehod I'm getting this:

email.append((0, 0, {'eproduct_id': rec[0],'eproduct_qty':rec[1],'emwosres':mwosres,'elms': lms, 'eqty_required':qtyreq,'ecurrent_stock': int(rec[2])}))
Inside this list is for example 5 products and I would like to put them in table straight into email .... how can I do it ?

@Yenthe How to include the xml file in __init__.py? Normally in __openerp__.py with 'data' : ['xx.xml'],?

@Mario my bad, I did mean the __openerp__.py file, I corrected my answer. :)

Nejlepší odpověď

Rob,

to loop throught the data which is not in current object, you can do that in python only, and send it to the template body...

you can get string of all the product details like this:

for lists in YOUR_DICTIONARY:

product_desc += """

<tr>

<td><b>%s</b></td>

<td> %s</td>

<td> %s</td>

.............[more_data]

</tr>

""" % (list['eproduct_id'], list['eproduct_qty'], list['emwosres']..........[more_data_reference])

then append it to the body
body = """

Hi,</br>

Please find Product details below:</br>

  <b><u>Product Details</u></b>: </br>

  <p>%s</p>

""" % (product_desc)

IF YOU DIRECTLY WANT TO SEND MAIL WITHOUT USING ANY TEMPLATE YOU CAN USE BELOW LOGIC

values = {}

values.update({'subject': 'Subject'})

values.update({'email_to': '[Email]'})

values.update({'body_html': body})

values.update({'body': body})

values.update({'res_id': ['CURRENT RECORD ID TO POST MESSAGE ON RECORD WALL']})

mail_mail_obj = self.pool.get('mail.mail')

msg_id = mail_mail_obj.create( cr, uid, values, context=context)

if msg_id:

mail_mail_obj.send(cr, uid, [msg_id], context=context)

OTHERWISE UPDATE THE BODY VALUE TO THE TEMPLATE AND SEND USING TEMPLATE ONLY

HOPE YOU GOT ME!!

Avatar
Zrušit
Autor

I would prefer to use template, much easier to customize.

Autor Nejlepší odpověď

By any chance, can I send an internal Odoo message instead or notification ?


Avatar
Zrušit

if you are having object in list[1], then use list[1].name, or if list[1] contains only product id then browse product master using this id and then get the product name before forming string...

Autor

Sounds complicated :(

Related Posts Odpovědi Zobrazení Aktivita
2
bře 24
10440
2
led 24
4273
2
led 24
9962
1
bře 21
9520
1
říj 20
7760