odooopenerp-7

How to update a field when I'm writing a value in other field in OpenERP 7?


I'm a newbie with openerp and I'm trying how can I need to know how can i make a code that calculates the result in a field when I write a value in other field, example:

field1 = 5000 

field2 = field1 * 5

I've read the docs and tried whit programming functions but always get an error.


Solution

  • Finally I solved it. I used this code:

    def _get_salario_diario(self, cr, uid, ids, field_name, arg, context=None):
        res= {}
        for record in self.browse(cr, uid, ids, context=context):
            res[record.id]= record.month_wage / 30
        return res
    _columns = {
        'month_wage': fields.float('Salario Mensual Bs.', digits=(16,2)),
        'diary_wage': fields.function(_get_salario_diario, method=True, type='float', string='Salario Diario Bs.', store=True),
    }
    
    def onchange_month_wage(self, cr, uid, ids, month_wage, context=None):
            vals = {}
            if month_wage > 0:
                vals['diary_wage'] = salario_mensual / 30
            return {'value': vals}
    

    and in my XML file:

    <field name='month_wage' on_change="onchange_month_wage(month_wage)"/>
    <field name='diary_wage'/>
    

    It solved my problem and my module works rightly.