Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
8511 Visualizzazioni

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
Abbandona
Risposta migliore

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

 

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

Avatar
Abbandona
Autore

version 7

Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
set 20
2992
0
apr 16
3295
3
mar 16
14146
1
mar 15
12545
1
apr 23
5238