Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
108 Переглядів

i tried to get a wizard by asking everything is filled correctlt and do cross check, when i change the state in to Closed Won - 100%

but im not able to do by onchange , contrains, write method. 
i tried using js file also but its not working 

can anyone help me to get solve this problem?? 

Аватар
Відмінити
Найкраща відповідь

1. Create a Wizard Model (Python)


# models/won_wizard.py
from odoo import models, fields

class CRMWonWizard(models.TransientModel):
    _name = 'crm.won.wizard'
    _description = 'Wizard triggered when deal is Closed Won'

    message = fields.Text(string="Message", default="You have marked this opportunity as Closed Won.")

    def action_confirm(self):
        return {'type': 'ir.actions.act_window_close'}



2. Define Wizard View (XML)

<!-- views/won_wizard_view.xml -->

<odoo>

    <record id="view_crm_won_wizard_form" model="ir.ui.view">

        <field name="name">crm.won.wizard.form</field>

        <field name="model">crm.won.wizard</field>

        <field name="arch" type="xml">

            <form string="Closed Won Confirmation">

                <group>

                    <field name="message" readonly="1"/>

                </group>

                <footer>

                    <button name="action_confirm" type="object" class="btn-primary" string="OK"/>

                </footer>

            </form>

        </field>

    </record>


    <record id="action_crm_won_wizard" model="ir.actions.act_window">

        <field name="name">Closed Won Wizard</field>

        <field name="res_model">crm.won.wizard</field>

        <field name="view_mode">form</field>

        <field name="view_id" ref="view_crm_won_wizard_form"/>

        <field name="target">new</field>

    </record>

</odoo>



3. Extend JS to Trigger Wizard

// static/src/js/crm_stage_wizard.js

odoo.define('your_module_name.crm_stage_wizard', function (require) {

    "use strict";


    const FormController = require('web.FormController');

    const core = require('web.core');

    const rpc = require('web.rpc');


    const Dialog = require('web.view_dialogs');


    FormController.include({

        _saveRecord: function () {

            const self = this;

            return this._super.apply(this, arguments).then(function (result) {

                if (self.modelName === 'crm.lead' && self.renderer.state.data.stage_id.display_name === 'Closed Won - 100%') {

                    rpc.query({

                        model: 'ir.actions.act_window',

                        method: 'search_read',

                        domain: [['res_model', '=', 'crm.won.wizard']],

                        fields: ['id'],

                        limit: 1,

                    }).then(function (actions) {

                        if (actions.length) {

                            self.do_action(actions[0].id);

                        }

                    });

                }

                return result;

            });

        },

    });

});



4. Load JS in Assets (XML)

<!-- views/assets.xml -->

<odoo>

    <template id="assets_backend" name="CRM Wizard Assets" inherit_id="web.assets_backend">

        <xpath expr="." position="inside">

            <script type="text/javascript" src="/your_module_name/static/src/js/crm_stage_wizard.js"/>

        </xpath>

    </template>

</odoo>



5. Don't forget to:

  • Add the wizard view and assets to your module’s __manifest__.py
  • Upgrade your module
  • Clear browser cache (for JS changes)


Why This JS Method Works :

  • _saveRecord is triggered after the user changes the stage and hits Save.
  • The JS checks if the stage_id name is "Closed Won - 100%".
  • If true, it finds the action linked to the wizard model and opens it using do_action().


Thanks & Regards,

Email :- contact@datainteger.com

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
1
лип. 23
1238
Hide Sales Menu in CRM Вирішено
1
черв. 23
1774
2
січ. 23
2780
1
бер. 15
5716
0
бер. 15
2854