Skip to Content
Menu
This question has been flagged

As you all know, Customer payments have 2 technical components : Account_voucher and Account_voucher_line.

On Customer Payments two fields interests me for the moment :

The amount field of account_voucher.

The amount field of account_voucher_line.

There is an onchange method on the field "amount" of account_voucher_line,

    def onchange_amount(self, cr, uid, ids, amount, amount_unreconciled, context=None):
        vals = {}
        if amount:
            vals['reconcile'] = (amount == amount_unreconciled)
        return {'value': vals}

 

it checks true if the amount is reconcilied, I want to return on the same onchange method the sum of every amount payed, for every voucher line, on the field amount of account.voucher.

So it's an onchange method from account_voucher_line into account_voucher.

I've tested a code, but it reacts on the field "amount" of account_voucher_line and not account_voucher.

It seems that there is a limitation, because, the onchange method works only on fields of the same model I guess.

Any recommandations for this issue ?

Avatar
Discard
Best Answer

There is a known bug with on_change and one2many field. Which version are you using?

 

https://github.com/odoo/odoo/issues/1711

Avatar
Discard
Author

version 7

Best Answer

You can solve this issue by following this workaround solution:

def onchange_employee_id(self, cr, uid, ids, employee_id, context=None):
        result = {'value': {'emp_contract_ids': False, 'emp_contract_ids_list': None}}
        emp_contract_ids = self.pool.get('hr.contract').search(cr, uid, [('employee_id', '=', employee_id)])
        if emp_contract_ids:
            result['value'] = { 'emp_contract_ids': emp_contract_ids, 'emp_contract_ids_list': emp_contract_ids}
        return result 
        
    _columns={
        'employee_id': fields.many2one('hr.employee', 'Employee', required=True),
        'emp_contract_ids': fields.one2many('hr.contract', 'employee_id', 'Employee Contracts', readonly=True), # a field just for user to see the results in the one2many widget as you want.
        'emp_contract_ids_list': fields.char('Employee Contracts ID List', invisible=True) # this field only to save the returned IDs from the onchange function and by then you can use it simply like that:

 

emp_contract_ids_list = map(int, emp_contract_ids_list.split(','))
for contract in self.pool.get('hr.contract').browse(cr, uid, emp_contract_ids_list):


    }

Avatar
Discard
Related Posts Replies Views Activity
0
Sep 20
2801
0
Apr 16
3147
3
Mar 16
13947
1
Mar 15
12352
1
Apr 23
5054