如何使用按钮向导生成新的线索?
How to generate new Lead with button wizard?
我正在尝试在日历活动中添加一个按钮 "Generate new Lead",用于复制有关此机会的所有内容并创建一个具有相同活动数据和时间的新潜在客户。
这是我的.py
class AnserCopy(models.TransientModel):
_name = 'anser.copy.wizard'
comments = fields.Text('Comments')
opportunity_id = fields.Many2one('crm.lead', string='Opportunity', domain="[('type', '=', 'opportunity')]")
tag_ids = fields.Many2many('crm.lead.tag', 'crm_lead_tag_rel', 'lead_id', 'tag_id', string='Tags', help="Classify and analyze your lead/opportunity categories like: Training, Service")
event_id = fields.Many2one('event.event', string='Event', required=True, ondelete='cascade')
@api.multi
def action_change_appointment_state(self):
wizards = self.browse(self._ids)
for wizard in wizards:
# get the lead to transform
event_id = wizard.event_id.copy()
opportunity_id = event_id.opportunity
opportunity_id = wizard.event_id.opportunity_id.copy()
opportunity_id.tag_ids = wizard.tag_ids
还有我的.xml
<record model="ir.ui.view" id="copy_wizard">
<field name="name">Copy Opportunity</field>
<field name="model">anser.copy.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Copy">
<group>
<field name="tag_ids" />
</group>
<footer>
<button type="object" name="action_change_appointment_state" string="Change State" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_copy" model="ir.actions.act_window">
<field name="name">Copy</field>
<field name="res_model">anser.copy.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record id="view_calendar_event_form_inherit6" model="ir.ui.view">
<field name="name">calendar.event.form.inherit6</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form"/>
<field name="arch" type="xml">
<sheet position="before">
<header>
<button name="%(action_copy)d" type="action" string="Gerar Nova Oportunidade" />
</header>
</sheet>
</field>
</record>
但是我的功能不起作用,谁能帮帮我?
我解决了:
class AnserMedicalCopy(models.TransientModel):
_name = 'anser_medical.copy_opportunity.wizard'
@api.model
def default_get(self, fields):
result = super(AnserMedicalCopy, self).default_get(fields)
event_id = self.env.context.get('active_id')
if event_id:
result['event_id'] = event_id
return result
tag_ids = fields.Many2many('crm.lead.tag', string='Tags', help="Classify and analyze your lead/opportunity categories like: Training, Service")
event_id = fields.Many2one('calendar.event', string='Event', required=True, ondelete='cascade')
@api.multi
def action_copy_opportunity(self):
wizards = self.browse(self._ids)
for wizard in wizards:
if wizard.event_id and wizard.event_id.opportunity_id:
event_id = wizard.event_id.copy()
event_id.opportunity_id = wizard.event_id.opportunity_id.copy()
event_id.opportunity_id.tag_ids = wizard.tag_ids
return {
'name': _('New Event'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'calendar.event',
'view_id': False,
'res_id': event_id.id,
'type': 'ir.actions.act_window',
'nodestroy': True
}
我正在尝试在日历活动中添加一个按钮 "Generate new Lead",用于复制有关此机会的所有内容并创建一个具有相同活动数据和时间的新潜在客户。
这是我的.py
class AnserCopy(models.TransientModel):
_name = 'anser.copy.wizard'
comments = fields.Text('Comments')
opportunity_id = fields.Many2one('crm.lead', string='Opportunity', domain="[('type', '=', 'opportunity')]")
tag_ids = fields.Many2many('crm.lead.tag', 'crm_lead_tag_rel', 'lead_id', 'tag_id', string='Tags', help="Classify and analyze your lead/opportunity categories like: Training, Service")
event_id = fields.Many2one('event.event', string='Event', required=True, ondelete='cascade')
@api.multi
def action_change_appointment_state(self):
wizards = self.browse(self._ids)
for wizard in wizards:
# get the lead to transform
event_id = wizard.event_id.copy()
opportunity_id = event_id.opportunity
opportunity_id = wizard.event_id.opportunity_id.copy()
opportunity_id.tag_ids = wizard.tag_ids
还有我的.xml
<record model="ir.ui.view" id="copy_wizard">
<field name="name">Copy Opportunity</field>
<field name="model">anser.copy.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Copy">
<group>
<field name="tag_ids" />
</group>
<footer>
<button type="object" name="action_change_appointment_state" string="Change State" class="btn-primary"/>
<button string="Cancel" class="btn-default" special="cancel"/>
</footer>
</form>
</field>
</record>
<record id="action_copy" model="ir.actions.act_window">
<field name="name">Copy</field>
<field name="res_model">anser.copy.wizard</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<record id="view_calendar_event_form_inherit6" model="ir.ui.view">
<field name="name">calendar.event.form.inherit6</field>
<field name="model">calendar.event</field>
<field name="inherit_id" ref="calendar.view_calendar_event_form"/>
<field name="arch" type="xml">
<sheet position="before">
<header>
<button name="%(action_copy)d" type="action" string="Gerar Nova Oportunidade" />
</header>
</sheet>
</field>
</record>
但是我的功能不起作用,谁能帮帮我?
我解决了:
class AnserMedicalCopy(models.TransientModel):
_name = 'anser_medical.copy_opportunity.wizard'
@api.model
def default_get(self, fields):
result = super(AnserMedicalCopy, self).default_get(fields)
event_id = self.env.context.get('active_id')
if event_id:
result['event_id'] = event_id
return result
tag_ids = fields.Many2many('crm.lead.tag', string='Tags', help="Classify and analyze your lead/opportunity categories like: Training, Service")
event_id = fields.Many2one('calendar.event', string='Event', required=True, ondelete='cascade')
@api.multi
def action_copy_opportunity(self):
wizards = self.browse(self._ids)
for wizard in wizards:
if wizard.event_id and wizard.event_id.opportunity_id:
event_id = wizard.event_id.copy()
event_id.opportunity_id = wizard.event_id.opportunity_id.copy()
event_id.opportunity_id.tag_ids = wizard.tag_ids
return {
'name': _('New Event'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'calendar.event',
'view_id': False,
'res_id': event_id.id,
'type': 'ir.actions.act_window',
'nodestroy': True
}