Skip to Content
Menu
This question has been flagged
1 Reply
5674 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')
    }   

Avatar
Discard
Best Answer

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.

Avatar
Discard
Author

great thanks.

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.

Related Posts Replies Views Activity
0
Mar 15
2905
1
Mar 15
10489
2
Oct 24
11153
3
Oct 17
15696
1
Oct 16
8987