Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
8382 Zobrazení

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
Zrušit
Nejlepší odpověď

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

 

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

Avatar
Zrušit
Autor

version 7

Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
0
zář 20
2858
0
dub 16
3203
3
bře 16
13994
1
bře 15
12414
1
dub 23
5137