如何在odoo9中传递上下文?

2024-06-08 01:05:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我想通过上下文将在销售订单中选择的合作伙伴_id传递给pricelist如何做到这一点?在

@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)

这里

^{pr2}$

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

当我传递上下文时,它说这接受4,我给了5。 现在我要在哪里改变它,所以它需要5。在


Tags: nameselfidlangpartnerifdomainorder
1条回答
网友
1楼 · 发布于 2024-06-08 01:05:40

因为新的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

相关问题 更多 >

    热门问题