我尝试向包含Odoo多个产品的多个合作伙伴发送电子邮件。
#OdepoOffer.py
# -*- coding: utf-8 -*-
from openerp import models, fields, api
"""
Class nomRelation Pour la gestion des noms des relations
"""
class odepoOffer(models.Model):
_name = 'odepo.offer'
name = fields.Char('Nom Offre' ,size=32)
odepoContactId = fields.Many2many('res.partner', ondelete='no action', string="Panier Clients")
odepoProductId = fields.Many2many('product.product', ondelete='no action', string="Panier Produits")
@api.multi
def email_partner(self):
'''
This function opens a window to compose an email, with the edi sale template message loaded by default
'''
self.ensure_one()
ir_model_data = self.env['ir.model.data']
try:
compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]
except ValueError:
compose_form_id = False
# It's worth noting that Odoo 9 uses 'mail.template' whereas Odoo 8 uses 'email.template'
# template_id = self.env['email.template'].search([('name', '=', 'Odepo Offer')], limit=1)
ctx = dict()
ctx.update({
'default_model': 'res.partner',
'default_res_id': False,
'default_use_template': True,
'default_template_id': False,
'default_composition_mode': 'comment',
'email_to':'testmail@gmail.com',
'subject':'mario',
'skip_notification': True,
})
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form_id, 'form')],
'view_id': compose_form_id,
'target': 'new',
'context': ctx,
}
# values['subject'] = val
# values['email_to'] = val1
# values['body_html'] = val2
# values['body'] = val3
# values['res_id'] = False
# values['attachment_ids'] = val4
和视图:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_odepo_offer_tree">
<field name="name">odepo.offer.tree</field>
<field name="model">odepo.offer</field>
<field name="arch" type="xml">
<form string="Odepo Offre">
<group>
<field name="name" string="Name"/>
<field name="odepoContactId" widget="many2many_tags" options="{'no_create_edit': True}"/>
<field name="odepoProductId" widget="many2many_tags" options="{'no_create_edit': True}"/>
<button name="email_partner" type="object" string="Create Email" class="oe_highlight"/>
</group>
</form>
</field>
</record>
<!--<record id="odepo_offer_email_header_form" model="ir.ui.view">
<field name="name">odepo.offer.header</field>
<field name="model">odepo.offer</field>
<field name="inherit_id" ref="view_odepo_offer_tree"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet" position="before">
<button name="email_partner" type="object" string="Create Email" class="oe_highlight"/>
</xpath>
</field>
</record>-->
<act_window id="action_view_wizard" name="Mr" res_model="odepo.offer" view_mode="tree,form"/>
<menuitem name="Gestion Des Offres" id="gestion_offer_id" parent="odepo_contact.odepo_config_id" sequence="10" />
<menuitem name="Noms Des Offres" id="sub_gestion_offer_id" parent="gestion_offer_id" sequence="11" action="action_view_wizard"/>
</data>
</openerp>
现在,我可以创建一个要约,并将其命名并用我的联系人填写odepoContactId,并用我的产品填写odepoProductId。
然后,我点击按钮发送电子邮件,我有一个弹出邮件撰写的向导。问题是,我无法将odepoContactId字段中的联系人添加到向导中弹出的邮件撰写中的收件人。我试图通过电子邮件地址抛出上下文,但没有运气
答案 0 :(得分:0)
您需要继承&#34; mail.compose.message&#34; 模型,因为在该模型中,所有合作伙伴都在那里。在该模型中&#34; partner_ids &#34;与&#34; res.partner &#34;是否存在may2many关系?
您可以参考销售