Skip to Content
Menu
This question has been flagged
1 Reply
1529 Views

In detail:

I have added 2 buttons Active and inactive in the form view. When i click active button the opportunity should move to Active column in kamban view. Same as when i click Inactive the opportunity should move to the inactive column in kamban view. Please help me to write the python code for the buttons.

button view:


kamban view:



Many thanks.

Avatar
Discard
Best Answer

You can do that as below :


Python code:


from odoo import models
class Lead(models.Model):
_inherit = "crm.lead"

def action_set_active(self):
self.stage_id = self._stage_find(domain=[('name', '=', 'Active')]).id

def action_set_inactive(self):
self.stage_id = self._stage_find(domain=[('name', '=', 'Inactive')]).id


Inherited CRM Form view:


<record id="crm_lead_view_form_update" model="ir.ui.view">
<field name="name">crm.lead.view.form.inherit.update</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_lead_view_form"/>
<field name="arch" type="xml">
<xpath expr="//header" position="inside">
<button name="action_set_active" string="Active" type="object" class="oe_highlight" />
<button name="action_set_inactive" string="Inactive" type="object" class="oe_highlight" />
</xpath>
</field>
</record>

Avatar
Discard
Author

Hi, I am facing this error:
forbidden opcode(s) in 'from odoo import models\r\n\r\nclass Lead(models.Model):\r\n _inherit = "crm.lead"\r\n\r\n def action_set_active(self):\r\n self.stage_id = self._stage_find(domain=[(\'name\', \'=\', \'Active\')]).id': IMPORT_NAME, IMPORT_FROM, LOAD_BUILD_CLASS

Hi, I have an issue in my provided code and I updated the code above and tested it in my local and its working. Could you please try it?

Author

Hi Waleed Mohsen, I am facing this error :
forbidden opcode(s) in 'lambda': STORE_ATTR
I have pasted exactly your code in the active button(server action) but I am facing this. Kindly help

Related Posts Replies Views Activity
1
Nov 22
2219
2
Aug 22
2178
2
May 22
1423
1
Mar 22
1705
1
Jun 24
968