gpt4 book ai didi

python - 如何在odoo9中传递上下文?

转载 作者:太空宇宙 更新时间:2023-11-03 16:14:22 25 4
gpt4 key购买 nike

我想通过上下文将销售订单中选择的partner_id传递给价目表,该怎么做?

@api.multi
@api.onchange('product_id')
def product_id_change(self):
if not self.product_id:
return {'domain': {'product_uom': []}}

vals = {}
domain = {'product_uom': [('category_id', '=', self.product_id.uom_id.category_id.id)]}
if not self.product_uom or (self.product_id.uom_id.category_id.id != self.product_uom.category_id.id):
vals['product_uom'] = self.product_id.uom_id

product = self.product_id.with_context(
lang=self.order_id.partner_id.lang,
partner=self.order_id.partner_id.id,
quantity=self.product_uom_qty,
date=self.order_id.date_order,
pricelist=self.order_id.pricelist_id.id,
uom=self.product_uom.id
)

name = product.name_get()[0][1]
if product.description_sale:
name += '\n' + product.description_sale
vals['name'] = name

self._compute_tax_id()

if self.order_id.pricelist_id and self.order_id.partner_id:
vals['price_unit'] = self.env['account.tax']._fix_tax_included_price(product.price, product.taxes_id, self.tax_id)
self.update(vals)
return {'domain': domain}

@api.onchange('product_uom', 'product_uom_qty')
def product_uom_change(self):
if not self.product_uom:
self.price_unit = 0.0
return
if self.order_id.pricelist_id and self.order_id.partner_id:
product = self.product_id.with_context(
lang=self.order_id.partner_id.lang,
partner=self.order_id.partner_id.id,
quantity=self.product_uom_qty,
date_order=self.order_id.date_order,
pricelist=self.order_id.pricelist_id.id,
uom=self.product_uom.id,
fiscal_position=self.env.context.get('fiscal_position')
)
self.price_unit = self.env['account.tax']._fix_tax_included_price(product.price, product.taxes_id, self.tax_id)

这里

vals['price_unit'] = self.env['account.tax']._fix_tax_included_price(product.price, product.taxes_id, self.tax_id)

我想传递partner_id上下文,这样我就可以检查特定的Bool是True还是False,并根据它进行计算。

当我传递上下文时,它说它接受 4 而我给出了 5。现在我该在哪里更改它,以便需要 5。

最佳答案

由于新的API上下文被封装在一个环境对象中,通常可以像self.env这样调用。要操作上下文,只需使用方法with_context。一个简单的例子:

vals['price_unit'] = self.env['account.tax']\
.with_context(partner_id=self.order_id.partner_id.id)\
._fix_tax_included_price(
product.price, product.taxes_id, self.tax_id)

有关更多信息,请查看 Odoo Doc

关于python - 如何在odoo9中传递上下文?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39039222/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com