我试图了解服务器操作,其中当状态从 更改为draft
时confirm
,会向提供的电子邮件发送一条消息。
程序中没有这样的错误,但邮件没有发送到自定义电子邮件。
代码如下:
notebook_server_action.xml:
<!-- demo automated actions sending message after state transition -->
<record id="filter_draft_lead" model="ir.filters">
<field name="name">Draft Leads notebook</field>
<field name="model_id">notebook.server_action</field>
<field name="domain">[('state','=','confirm')]</field>
<field name="user_id" eval="False" />
</record>
<record id="action_email_reminder_lead" model="ir.actions.server">
<field name="name">Message @ confirm state</field>
<field name="model_id" ref="model_notebook_server_action" />
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="state">email</field>
<field name="email">object.email</field>
<field name="subject">Check 1 2 3</field>
<field name="message">11111111111111</field>
</record>
<record id="rule_set_reminder_lead" model="base.action.rule">
<field name="name">Send mail when status changed to confirm</field>
<field name="model_id" ref="model_notebook_server_action" />
<field name="sequence">1</field>
<field name="filter_id" ref="filter_draft_lead" />
<field name="trg_date_id" ref="field_notebook_server_action_note_date" />
<field name="trg_date_range">0</field>
<field name="trg_date_range_type">minutes</field>
<field name="server_action_ids" eval="[(6,0,[ref('action_email_reminder_lead')])]" />
</record>
笔记本.py
class notebook(osv.osv):
_name = "notebook.server_action"
_description = "Simple Notebook"
_columns = {
'name' : fields.char('Title', size=30, required=True),
'note' : fields.text('Note'),
'email': fields.char('Email', size=120, required=True),
'note_date' : fields.datetime('Date'),
'state': fields.selection([('draft', 'Draft'), ('confirm', 'Confirmed')],
'Status', required=True, readonly=True),
}
_defaults = {
'state': 'draft',
'note_date' : lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
}
def button_confirm(self, cr, uid, ids, context=None):
return self.write(cr, uid, ids, {'state': 'confirm'})
notebook_view.xml
<record model="ir.ui.view" id="notebook_server_actiontree_view">
<field name="name">notebook.server_action.tree</field>
<field name="model">notebook.server_action</field>
<field name="arch" type="xml">
<tree string="Notebook">
<field name="name" />
<field name="note" />
<field name="note_date" />
</tree>
</field>
</record>
<record model="ir.ui.view" id="notebook_server_actionform_view">
<field name="name">notebook.server_action.form</field>
<field name="model">notebook.server_action</field>
<field name="arch" type="xml">
<form string="Notebook" version="7.0">
<header>
<button name="button_confirm" states="draft" string="Confirm"
type="object" />
<field name="state" widget="statusbar" />
</header>
<sheet>
<group>
<field name="name" />
<field name="note" />
<field name="note_date" />
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_notebook_server_actionform">
<field name="name">notebook.server_action</field>
<field name="res_model">notebook.server_action</field>
</record>
<menuitem name="NotebookParent" icon="terp-project" id="NotebookParent_menu" />
<menuitem name="NotesChild" parent="NotebookParent_menu" id="NotesChild_menu" />
<menuitem name="Header" parent="NotesChild_menu" id="Header_menu_mainform"
action="action_notebook_server_actionform" />