Search code examples
pythonapiodoo-8

How to pass id argument while calling an old api method from a new api method in odoo


Currently i am working on odoo8. I have a function written in new API as,

@api.onchange('scheme','product_id','product_uos_qty')
@api.constrains('scheme','product_id','product_uos_qty')
def change_sale_price_scheme(self):
    if self.scheme:
        get_product_wise_tax = self.pool.get('sale.order.line').calx_amount_line_tax(self._cr, self.env.uid, id=?, self._context)
             ....
            ....

from above function i am calling an old api function. Old api function is given below

    @api.v7
    def calx_amount_line_tax(self, cr, uid, ids, context=None):
        for order in self.pool('sale.order').browse(cr, uid, ids, context=context):
            for line in order.order_line:
                val = 0.0
                line_obj = self.pool['sale.order.line']
                price = line_obj._calc_line_base_price(cr, uid, line, context=context)
                qty = line_obj._calc_line_quantity(cr, uid, line, context=context)
                for c in self.pool['account.tax'].compute_all(
                        cr, uid, line.tax_id, price, qty, line.product_id,
                    line.order_id.partner_id)['taxes']:
                    val += c.get('amount', 0.0)
        return val

Here how can i pass the id while calling the old api function?


Solution

  • Finally after a long search I found the answer. What I did is..

    @api.onchange('scheme','product_id','product_uos_qty')
    @api.constrains('scheme','product_id','product_uos_qty')
    def change_sale_price_scheme(self):
        if self.scheme:
           self.foo()
    
    
    @api.cr_uid_ids_context
    def foo(self,cr,uid,ids,context=None):
        get_product_wise_tax = self.pool.get('sale.order.line').calx_amount_line_tax(cr,uid,ids,context)
    
    @api.v7
    def calx_amount_line_tax(self, cr, uid, ids, context=None):
        .........
    

    @api.cr_uid_ids_context: This will decorate a traditional-style method that takes 'cr', 'uid', 'ids', 'context' as parameters. Such a method:

    So the function will automatically takes all parameters

    For further knowledge refer : http://abhishek-jaiswal.github.io/blog/odoov8/2014/11/15/odoo-v8-decorator.html