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 can i call an api.v7 decorator function from a 'models.Model' class?

By
Pablo Archanco
on 6/14/16, 4:43 AM 271 views

In the model account.tax  (account/account.py) there are two functions compute_all and i want to call which has the @api.v7 decorator. 

Im trying from a function with @api.model but it is always being called the @api.v8 function. i need to calculate the taxes of a product and the api.v8 takes the taxes from self, i want to pass as a parameter.

Thanks.

@api.v7def compute_all(self, cr, uid, taxes, price_unit, quantity, product=None, partner=None, force_excluded=False):    """    :param force_excluded: boolean used to say that we don't want to consider the value of field price_include of        tax. It's used in encoding by line where you don't matter if you encoded a tax with that boolean to True or        False    RETURN: {            'total': 0.0,                # Total without taxes            'total_included: 0.0,        # Total with taxes            'taxes': []                  # List of taxes, see compute for the format        }    """    # By default, for each tax, tax amount will first be computed    # and rounded at the 'Account' decimal precision for each    # PO/SO/invoice line and then these rounded amounts will be    # summed, leading to the total amount for that tax. But, if the    # company has tax_calculation_rounding_method = round_globally,    # we still follow the same method, but we use a much larger    # precision when we round the tax amount for each line (we use    # the 'Account' decimal precision + 5), and that way it's like    # rounding after the sum of the tax amounts of each line    precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Account')    tax_compute_precision = precision    if taxes and taxes[0].company_id.tax_calculation_rounding_method == 'round_globally':        tax_compute_precision += 5    totalin = totalex = round(price_unit * quantity, precision)    tin = []    tex = []    for tax in taxes:        if not tax.price_include or force_excluded:            tex.append(tax)        else:            tin.append(tax)    tin = self.compute_inv(cr, uid, tin, price_unit, quantity, product=product, partner=partner, precision=tax_compute_precision)    for r in tin:        totalex -= r.get('amount', 0.0)    totlex_qty = 0.0    try:        totlex_qty = totalex/quantity    except:        pass    tex = self._compute(cr, uid, tex, totlex_qty, quantity, product=product, partner=partner, precision=tax_compute_precision)    for r in tex:        totalin += r.get('amount', 0.0)    return {        'total': totalex,        'total_included': totalin,        'taxes': tin + tex    }@api.v8def compute_all(self, price_unit, quantity, product=None, partner=None, force_excluded=False):    return account_tax.compute_all(        self._model, self._cr, self._uid, self, price_unit, quantity,        product=product, partner=partner, force_excluded=force_excluded)


0
kirubanidhi
On 6/14/16, 6:08 AM
@api.v8

def compute_all(self, taxes, price_unit, quantity, product=None, partner=None, force_excluded=False):

precision = self.pool.get('decimal.precision').precision_get( 'Account')

tax_compute_precision = precision

if taxes and taxes[0].company_id.tax_calculation_rounding_method == 'round_globally':

tax_compute_precision += 5

totalin = totalex = round(price_unit * quantity, precision)

tin = []

tex = []

for tax in taxes:

if not tax.price_include or force_excluded:

tex.append(tax)

else:

tin.append(tax)

tin = self.compute_inv( tin, price_unit, quantity, product=product, partner=partner, precision=tax_compute_precision)

for r in tin:

totalex -= r.get('amount', 0.0)

totlex_qty = 0.0

try:

totlex_qty = totalex/quantity

except:

pass

tex = self._compute( tex, totlex_qty, quantity, product=product, partner=partner, precision=tax_compute_precision)

for r in tex:

totalin += r.get('amount', 0.0)

return

{ 'total': totalex,

'total_included': totalin,

'taxes': tin + tex

}


 Try this code


0
Pablo Archanco
On 6/14/16, 6:52 AM

I have gotten otherwise, here is an example
Many thanks for answer

account_tax = self.env['account.tax']
taxes = account_tax.browse(product_id['invoice_line_tax_id'][0][2])
taxes.compute_all( product_id['price_unit'], product_id['quantity'], product_id['product_id'], invoice['partner_id'], force_excluded=False)



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: 6/14/16, 4:43 AM
Seen: 271 times
Last updated: 6/14/16, 6:52 AM