我创建了一个自动操作,如果When to Run
设置为On Creation
,它可以正常工作。如果我将其更改为Based on Timed Condition
则不会触发。
服务器操作
我该怎么做?
答案 0 :(得分:0)
您必须通过python代码执行此操作。你试过吗?
我有一个例子:对于合作伙伴通知电子邮件发送:通过操作:
<record id="action_send_mail_on_partner_creation" model="ir.actions.server">
<field name="name">Partner Creation action</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">self.parnter_create_notification(cr, uid, object, context=context)</field>
</record>
<record id="rule_sent_mail_partner_creation" model="base.action.rule">
<field name="name">Partner Creation Action Rule</field>
<field name="kind">on_create_or_write</field>
<field name="model_id" ref="base.model_res_partner"/>
<field name="sequence">1</field>
<field name="filter_id" ref="filter_customer"/>
<field name="active">True</field>
<field name="server_action_ids" eval="[(6, 0, [ref('action_send_mail_on_partner_creation')])]"/>
</record>
您必须在PY文件中定义的方法是:
def parnter_create_notification(self, cr, uid, obj, context=None):
if context.get('from_create',False):
group_obj = self.pool.get('res.groups')
user_obj = self.pool.get('res.users')
if obj.customer or obj.supplier:
manager_ids = group_obj.search(cr, uid, [('name','=', 'Financial Manager')])
user_ids = group_obj.browse(cr, uid, manager_ids, context=context)[0].users
email = []
for id in user_ids:
email.append(id.email)
email_to = ','.join(str(e) for e in email)
tmpl_obj = self.pool.get('email.template')
tmpl_ids = tmpl_obj.search(cr, uid, [('name','=','Partner E-mail Template')])
if tmpl_ids:
tmpl_obj.write(cr, uid, tmpl_ids[0], {'email_to':email_to}, context=context)
self.pool.get('email.template').send_mail(cr, uid, tmpl_ids[0], obj.id)
return {}
在res.partner的继承类中。
您可以针对您的问题采用此示例。
希望这会对你有所帮助。
谢谢, 月光