Hi
I'm trying to add a button "Generate new Lead" inside a calendar event that copy's everything about this opportunity and creates a new Lead with the same data and hours of the event.
this is my .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
and my .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>
But my function is not working, can anyone help me?
Do you want to create a record in CRM when you click on this button?
yes!