目前我正在研究odoo8。我有一个用新API编写的函数,
@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)
....
....
从上面的函数我调用一个旧的api函数。旧api函数如下所示
@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
这里如何在调用旧的api函数时传递id?
答案 0 :(得分:0)
经过长时间的搜索,我找到了答案。 我做的是......
@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:这将装饰传统风格的方法 需要'' uid',' ids'' context'作为参数。这样的方法:
因此该函数将自动获取所有参数
有关进一步的知识,请参阅:http://abhishek-jaiswal.github.io/blog/odoov8/2014/11/15/odoo-v8-decorator.html