Odoo Help

Welcome!

This community 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.

0

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

By
Pascal Tremblay
on 2/3/16, 7:40 PM 446 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 $.


Possible???

Thanks

UPDATE #1

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')
    }   

1
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 2/3/16, 7:40 PM
Seen: 446 times
Last updated: 2/4/16, 4:43 PM