我想尝试从同一模块中的server action调用python方法。但是没有找到错误但是没有调用该方法。我也关注此链接for call the python method。这是我用来调用方法的代码。
.XML
<record id="action_email_data_parser_server" model="ir.actions.server" >
<field name="name">[Server Action] Create Leads from Mail</field>
<field name="model_id" ref="model_email_data_parser"/>
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
lead = self.browse(cr, uid, context['active_id'], context=context)
mail_message = lead.message_ids[0]
mail_body = mail_message['body']
lead_data_dict = self.parse_body(cr, uid, mail_body)
self.write(cr, uid, context['active_id'], lead_data_dict)
</field>
</record>
的.py
class email_data_parser(osv.osv):
_name = "email_data_parser"
_description = "Email Data Parser"
def parse_body(self, uid, body):
data_dist = body
retun data_dist
所以,如果有任何人有任何想法请与我分享,我该如何解决这个问题。
答案 0 :(得分:1)
我得到了答案,当您想要触发任何服务器操作时,您只需遵循此代码,这可能会对您有所帮助。
.xml
<record id="action_email_data_parser_server" model="ir.actions.server" >
<field name="name">[Server Action] Create Leads from Mail</field>
<field name="model_id" ref="model_email_data_parser"/>
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
action = self.parse_body(cr, uid, context=context)
</field>
</record>
的.py
import logging
from openerp.osv import fields,osv,expression
from openerp import models,api
_logger = logging.getLogger(__name__)
class email_data_parser(osv.osv):
_name = "email_data_parser"
_description = "Email Data Parser"
def parse_body(self, cr, uid, context=None):
_logger.info('This is FDS email parsing and through we can parse the mail from any email')
然后在odoo-server.log中检查它。如果消息显示,那么你的服务器动作将调用python方法。
答案 1 :(得分:0)
{{1}}