Performance killing functional field in account_move_line
In the base code of ./account_banking_payment_export/model/account_move_line.py
is a functional field delcared
_inherit = 'account.move.line'
def amount_to_pay(self, cr, uid, ids, name, arg=None, context=None):
""" Return the amount still to pay regarding all the payemnt orders
(excepting cancelled orders)"""
if not ids:
CASE WHEN ml.amount_currency < 0
THEN - ml.amount_currency
FROM payment_line pl
INNER JOIN payment_order po
ON (pl.order_id = po.id)
WHERE move_line_id = ml.id
AND po.state != 'cancel') AS amount
FROM account_move_line ml
WHERE id IN %s""", (tuple(ids),))
r = dict(cr.fetchall())
'amount_to_pay': fields.function(amount_to_pay,type='float', string='Amount to pay', fnct_search=_to_pay_search),
when i use this field in a loop...
for line in move_obj.browse(cr, uid, move_ids, context):
if line.amount_to_pay > 0.00
The moment it read the if line.amount_to_pay > 0.00 it generates a huge query on the postgres DB, i believe for all the account_move_line.
I was expecting just a query for one line, but this is not so...
Has anybody had the same experience with such an issue?