I have a `One2Many` field which has some products and I want to get the "Cost" of these products. I don't have much time which I started in odoo and this is mid difficult for me yet to achieve. Can someone help me?
At the moment what I have only done is this:
class ComboProductTemplate(models.Model):
_inherit = "product.template"
is_combo = fields.Boolean('Combo Product', default=False)
combo_product_id = fields.One2many('product.combo', 'product_template_id', 'Combo Item')
product_cost_id = fields.Many2one("product.product", 'standard_price')
combo_price = fields.Float("Combo Price: ", compute='_compute_combo_price')
def _compute_combo_price(self):
products = self.env['product.product'].search([('standard_price', '=', self.standard_price)])
for ids in products:
print(ids.ids)
unique_variants = self.filtered(lambda template: len(template.product_variant_ids) == 1)
print(unique_variants)
for template in unique_variants:
print(f"TEMPLATE: {template}")
template.standard_price = template.product_variant_ids.standard_price
print(template.standard_price)
for template in (self - unique_variants):
print("here")
template.standard_price = 0.0
The computed function will get the `standard_price` of current product I click.
What I except:
Get the products on `one2many` field and get each one of them `standard_price`.
What am I getting?
At the moment I'm only getting the only one product `standard_price`
Please post your code to get a help.
@Waleed Mohsen, thanks for reply, I updated my question. Hope you can land a thought.