Ir al contenido
Menú
Se marcó esta pregunta
3715 Vistas


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
Descartar
Autor

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.

Publicaciones relacionadas Respuestas Vistas Actividad
3
feb 25
3498
0
may 24
46
1
abr 24
3328
4
sept 23
4815
2
sept 23
7031