Odoo Help


[8.0] [API] Computed Fields - Using the Search Function

on 6/5/15, 10:58 AM 2,159 views

 I implemented a computed field like below:

class AccountAnalyticAccount(models.Model):
_inherit = 'account.analytic.account'

balance2 = fields.Float(string="Balanced", compute='_balance', search='_search_balanced')
# debit = fields.Float(compute='_debit_credit_bal_qttyi')
# credit = fields.Float(compute='_debit_credit_bal_qttyi')
# quantity = fields.Float(compute='_debit_credit_bal_qttyi')
def _search_balanced(self, operator, operand):
'''Search the functional field balance'''
# for some reason, this method never gets called!

FROM account_analytic_account a LEFT JOIN account_analytic_line l on (a.id=l.account_id)
''' + operator + ' ' + float(operand)
rows = self.env.cr.fetchall()
res = [('ids', 'in', rows)]
if not (rows):
res = 0.0
return res

def _balance(self):
for acct in self:
acct.balance2 = acct.balance
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

As you can see, I have a pdb.set_trace() in there and would expect that I would get to the breakpoint when I run a command with that field in the domain.  Instead, when I run the following from XML-RPC, I get all the rows that have parent_id.code == 'RET001', but I get all rows that have 0.0 in the balance without ever running into my trace:

res = self._model.execute_kw(self._db,self.uid, self._pwd,"account.analytic.account","search",[[('balance2', '!=', '0.0'),('parent_id.code','=','RET001')]],{}) 

How do I implement computed field search correctly?

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/5/15, 10:58 AM
Seen: 2159 times
Last updated: 6/8/15, 9:59 AM