Odoo Help


How to display difference of debit and credit on a tree view?

Pascal Tremblay
on 2/3/16, 7:40 PM 937 views

Hello all,

How could I display somewhere on this tree view the difference between the debit and the credit.

Here, I would want somewhere displayed : 1524,58 - 9,75 = 1514,82 $.




I have used this code finally :

class account_move_line(osv.osv):
    _inherit = "account.move.line"
    #_logger.error("result_calcasdgfas dfsdfg sdfg asdfg sdf")
    def _result_calc(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for aml in self.browse(cr, uid, ids, context=context):
            res[aml.id] =  aml.credit - aml.debit
        return res   
    _columns = {
        'result': fields.function(_result_calc, type='float', string='Total result')

Gerhard Baumgartner
On 2/4/16, 6:17 AM

If you want to have the exact string "1524,58 - 9,75 = 1514,82 $." I would recommend making a new field where you compute the difference. 

def _calc_diff(self):
     self.diff = self.debit-self.credit

diff = fields.Float(compute=_calc_diff)

And another field where you create a String with the exact format.

def _build_str(self):
    self.string = str(self.debit) + " - " + str(self.credit) + " = " + str(self.diff)  + " $"

string = fields.Char(compute=_build_str)

Add the new fields to your xml and that should be it.

great thanks.

Pascal Tremblay
on 2/4/16, 7:35 AM

If you inherit the original model and you're working with odoo 8 or 9 it should work for sure. If you add to the original you'd just need to try, never tried mixing oldstyle fields and newstyle fields myself. If you're using an older version this new style won't work, but the logic is the same.

Gerhard Baumgartner
on 2/4/16, 4:34 PM

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: 2/3/16, 7:40 PM
Seen: 937 times
Last updated: 2/4/16, 4:43 PM