Odoo Help


Another onchange not working... [Closed]

Christian Ruppenthal
on 9/25/13, 10:35 AM 971 views

The Question has been closed for reason: duplicate question

Andreas Brueckl
on 09/25/2013 10:54:55

Hello helpers!

I'm working on an extension module for CRM to use with cellphone plan sales and I ran into a problem. Basically what I need is to store date and time on some custom fields on the cdm.lead model. Those fields should record the date and time when an opportunity changes stage to three stages I want to monitor.

Here's what I have now:

**crm_lead.py (on my custom module)**
class crm_lead(orm.Model):
    _inherit = "crm.lead"

    def onchange_stage_id(self, cr, uid, ids, stage_id, context=None):
        if not stage_id:
            return {'value':{}}
        stage = self.pool.get('crm.case.stage').browse(cr, uid, stage_id, context)
        if not stage.on_change:
            return {'value':{}}
        return {'value':{'probability': stage.probability}}
        for record in self.browse(cr, uid, ids):
                record.data_mod_est = fields.datetime.now()
                if stage.name == "Envio":
                        record.data_envio = fields.datetime.now()
                elif stage.name == "Cadastro":
                        record.data_cadastro = fields.datetime.now()
                elif stage.name == "Ativacao":
                        record.data_ativacao = fields.datetime.now()
    _columns = {
        'data_envio': fields.datetime('Data de envio'),
        'data_cadastro': fields.datetime('Data de cadastro'),
        'data_ativacao': fields.datetime('Data de ativacao')

And the view...

                   <!-- CRM Opportunity Form View -->
                    <record model="ir.ui.view" id="l10n_br_crm_case_form_view_oppor1">
                            <field name="name">l10n_br_crm.opportunities1</field>
                            <field name="model">crm.lead</field>
                            <field name="inherit_id" ref="crm.crm_case_form_view_oppor" />
                            <field name="arch" type="xml">
                                    <field name="stage_id" position="replace">
                                            <field name="stage_id" widget="statusbar" clickable="True" on_change="onchange_stage_id(stage_id)"/>
                                    <field name="categ_ids" position="after">
                                            <field name="data_envio" />
                                            <field name="data_cadastro" />
                                            <field name="data_ativacao" />

My problem is that when stages change, the fields are not updated. Can someone shed some light on my code?

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 9/25/13, 10:35 AM
Seen: 971 times
Last updated: 3/16/15, 8:10 AM