Odoo Help


sum of total amount in treeview.

on 9/2/13, 2:39 AM 3,192 views

How to find the total amount in the treeview of openerp v7.0

i need the python code for implementing it in a new module. please provide it .

In the salesorder there appears the total amount in the tree view. That what i need. Any members please provide the corresponding function in the sales.py for

On 9/2/13, 10:40 AM

The functions you need are :

import openerp.addons.decimal_precision as dp
    class sale_order(osv.osv):
        def _amount_line_tax(self, cr, uid, line, context=None):
            val = 0.0
            for c in self.pool.get('account.tax').compute_all(cr, uid, line.tax_id, line.price_unit * (1-(line.discount or 0.0)/100.0), line.product_uom_qty, line.product_id, line.order_id.partner_id)['taxes']:
                val += c.get('amount', 0.0)
            return val

        def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
            cur_obj = self.pool.get('res.currency')
            res = {}
            for order in self.browse(cr, uid, ids, context=context):
                res[order.id] = {
                    'amount_untaxed': 0.0,
                    'amount_tax': 0.0,
                    'amount_total': 0.0,
                val = val1 = 0.0
                cur = order.pricelist_id.currency_id
                for line in order.order_line:
                    val1 += line.price_subtotal
                    val += self._amount_line_tax(cr, uid, line, context=context)
                res[order.id]['amount_tax'] = cur_obj.round(cr, uid, cur, val)
                res[order.id]['amount_untaxed'] = cur_obj.round(cr, uid, cur, val1)
                res[order.id]['amount_total'] = res[order.id]['amount_untaxed'] + res[order.id]['amount_tax']
            return res

        def _get_order(self, cr, uid, ids, context=None):
            result = {}
            for line in self.pool.get('sale.order.line').browse(cr, uid, ids, context=context):
                result[line.order_id.id] = True
            return result.keys()

        _columns = {
            'amount_untaxed': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Untaxed Amount',
                    'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
                    'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
                multi='sums', help="The amount without tax.", track_visibility='always'),
            'amount_tax': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Taxes',
                    'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
                    'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
                multi='sums', help="The tax amount."),
            'amount_total': fields.function(_amount_all, digits_compute=dp.get_precision('Account'), string='Total',
                    'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
                    'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
                multi='sums', help="The total amount."),

My answer helps you ?

on 9/3/13, 5:38 AM

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

0 follower(s)


Asked: 9/2/13, 2:39 AM
Seen: 3192 times
Last updated: 3/16/15, 8:10 AM