Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
8388 Widoki

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 ?

Awatar
Odrzuć
Najlepsza odpowiedź

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

 

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

Awatar
Odrzuć
Autor

version 7

Najlepsza odpowiedź

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):


    }

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
wrz 20
2865
0
kwi 16
3204
3
mar 16
13998
1
mar 15
12415
1
kwi 23
5145