Odoo Help


How to get the correct value of tax in SALES??

on 11/25/14, 3:53 AM 1,487 views

Why does it did not get the correct computation for tax?  here my codes:

class sale_order(osv.osv):
    _inherit = "sale.order"
    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)) *(1-(line.bo_disc or 0.0)/100.0)* (1-(line.cod_disc 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_lines:
                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)
            netsvc.Logger().notifyChannel("-----------------222..",netsvc.LOG_INFO, '' +'' + str(res[order.id]['amount_tax']))
            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()  
    _column = {
               'discount': fields.float('Discount 1(%)', digits_compute= dp.get_precision('Discount'), readonly=True, states={'draft': [('readonly', False)]}),
               'disc_amount' : fields.float('Disccount Amount', digits=(10,7)),
               'bo_disc' :fields.float('Discount 2(%)', digits=(10,2)),
               'bo_amount':fields.float('BO Amount', digits=(10,7)),
               'cod_disc' :fields.float('Discount 3(%)', digits=(10,2)),
               'cod_amount' :fields.float('COD Amont', digits=(10,7)),
        '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."),





Alejandro Perez Cosio
On 11/26/14, 7:45 AM

Hello Alcaline Lee, you should check this portion of code in order to understand how odoo is calculating the invoices amount:

account/account.py > _unit_compute_inv(...) > 

if tax.include_base_amount:
    amount = cur_price_unit - (cur_price_unit / (1 + tax.amount))
    amount = (cur_price_unit / (1 + tax_parent_tot)) * tax.amount

You can use some debugging tool like ipdb to check if the values are the expected ones, your with ipdb should look like: 


import ipdb; ipdb.set_trace()
if tax.include_base_amount:
    amount = cur_price_unit - (cur_price_unit / (1 + tax.amount))

    amount = (cur_price_unit / (1 + tax_parent_tot)) * tax.amount

Kibong Moon
On 11/27/14, 2:02 AM

Hi Alcaline Lee,

Is there any specific reason for you to have to custom develop the codes for tax calculation in sales order? Because I thought it is a function that should work fine out of the box.



P.S. 오두 커뮤니티에서 활발하게 활동하시는 한국분을 보니 너무 반갑습니다. 저희 회사는 올해부터 활동하고 있는 오두의 한국 공식파트너이고, 제 이메일은 kibong@mondays.kr 입니다. 여러가지로 제가 도움받을 수 있을 것 같으니 꼭 이메일 부탁드립니다. 감사합니다.

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 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: 11/25/14, 3:53 AM
Seen: 1487 times
Last updated: 3/16/15, 8:10 AM