是否可以将Suport Ticket转换为Project>任务。
任务标题=支持主题,任务描述=支持描述...
示例:
我使用此模块https://www.odoo.com/apps/modules/9.0/website_support/
在我想要的支持票中添加:
下面是新函数def generate_task(self):如何从中生成新的TASK。
class WebsiteSupportTicketCompose(models.Model):
_name = "website.support.ticket.compose"
ticket_id = fields.Many2one('website.support.ticket', string='Ticket ID')
partner_id = fields.Many2one('res.partner', string="Partner", readonly="True")
email = fields.Char(string="Email", readonly="True")
subject = fields.Char(string="Subject", readonly="True")
body = fields.Html(string="Message Body")
template_id = fields.Many2one('mail.template', string="Mail Template", domain="[('model_id','=','website.support.ticket')]")
@api.onchange('template_id')
def _onchange_template_id(self):
if self.template_id:
values = self.env['mail.compose.message'].generate_email_for_composer(self.template_id.id, [self.ticket_id.id])[self.ticket_id.id]
self.body = values['body']
@api.one
def send_reply(self):
#Send email
values = {}
email_wrapper = self.env['ir.model.data'].get_object('website_support','support_ticket_reply_wrapper')
values = email_wrapper.generate_email([self.id])[self.id]
values['model'] = "website.support.ticket"
values['res_id'] = self.ticket_id.id
send_mail = self.env['mail.mail'].create(values)
send_mail.send()
#(Depreciated) Add to message history field for back compatablity
self.env['website.support.ticket.message'].create({'ticket_id': self.ticket_id.id, 'content':self.body.replace("<p>","").replace("</p>","")})
#Post in message history
#self.ticket_id.message_post(body=self.body, subject=self.subject, message_type='comment', subtype='mt_comment')
staff_replied = self.env['ir.model.data'].get_object('website_support','website_ticket_state_staff_replied')
self.ticket_id.state = staff_replied.id
@api.one
def generate_task(self):
values = {}
print(self.ticket_id.id)
print(self.email)
print(self.subject)
print(self.body.replace("<p>","").replace("</p>",""))
#How this data insert in new TASK
任何简单的解决方案?
答案 0 :(得分:0)
尝试以下代码:
@api.multi
def generate_task(self,cr, uid, ids, context=None):
Task = self.pool["project.task"]
vals = {
"name": "TEST",
"description": "DESCRIPTION",
}
task_id = Task.create(cr,uid,vals,context=None)
task = Task.browse(cr,uid,task_id,context=None)