Skip to Content
Menu
This question has been flagged
3699 Views


Hi ,

I want to get value of standard_price of the main company in compute field of standard_price.
I tried with this code but showing always 'False' value.
Any help please ??

Here is my code:

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


    ***Result : ------st_price:False

Thanks

Avatar
Discard
Author

The main objective was : I have company A with Inventory valuation configuration (avco/automated) and company B with Inventory valuation configuration (standard/manual) If I have standard_price value in company A,when I switch from company A to B, I want to get same value in company B , actually I get always 0.0 value.

Related Posts Replies Views Activity
3
Feb 25
3421
0
May 24
46
1
Apr 24
3298
4
Sep 23
4780
2
Sep 23
6988