我想在标准价格的计算字段中得到主公司的标准价格值。 我尝试使用此代码,但始终显示“False”值
有什么帮助吗
这是我的密码:
class ProductTemplate(models.Model):
_inherit = "product.template"
@api.depends_context('company')
@api.depends('product_variant_ids', 'product_variant_ids.standard_price')
def _compute_standard_price(self):
st_price = self.env['ir.property']._get(self.with_context(company=self.env.ref('base.main_company')).standard_price,"product.product")
_logger.info('------st_price:%s', st_price)
# Depends on force_company context because standard_price is company_dependent
# on the product_product
unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1)
for template in unique_variants:
template.standard_price = template.product_variant_ids.standard_price
for template in (self - unique_variants):
template.standard_price = 0.0
结果:----st_价格:假
谢谢
您需要使用
force_company
作为上下文标志并“重新加载”记录:相关问题 更多 >
编程相关推荐