Community mailing list archives

community@mail.odoo.com

Re: Update field on another field change

by
Vauxoo S.A. de C.V., Humberto
- 10/16/2014 14:02:57

Here you can find how residual field
Is computed
https://github.com/odoo/odoo/blob/8.0/addons/account/account_invoice.py#L298
https://github.com/odoo/odoo/blob/8.0/addons/account/account_invoice.py#L106

Quien suscribe,

Hbto

Hi dear Developers.
Can please anybody give a clue how to update a field when another field is changed.
I have a model with the following fields: state,  start_time, end_time.
I need to have an update trigger to record start_time / end_time on state change.

state = fields.Selection(SESSION_STATE_CHOICES, string=_('State'))
start_time = fields.Datetime(string=_('Started'))
end_time = fields.Datetime(string=_('Ended'))

>From the documentation:

 This decorator will trigger the call to the decorated function if any of the fields specified in the decorator is altered by ORM or changed in the form:

    @api.multi
    @api.depends('state')
    def _on_state_change(self):
        _logger.debug('SESSION STATE CHANGE: %s' % self.state)
        for rec in self:
            if rec.state == 'running':
                rec.start_time = datetime.datetime.now()
            elif rec.state in ['done', 'cancelled']:
                rec.end_time = datetime.datetime.now()


_on_state_change is never called!


Tried to use field inverse attribute. Like this:
state = fields.Selection(SESSION_STATE_CHOICES, inverse='_on_state_change', string=_('State'))
Also does not work. _on_change_state is never called.

So. How to update one field when another one is changed?
Thanks.

_______________________________________________
Mailing-List: https://www.odoo.com/groups/community-59
Post to: mailto:community@mail.odoo.com
Unsubscribe: https://www.odoo.com/groups?unsubscribe