Odoo Help


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.


sum of total amount in treeview.

on 9/2/13, 2:39 AM 2,118 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

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

0 follower(s)


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