Skip to Content
Menu
This question has been flagged
2 Replies
673 Views

Hi , 

I had two class :


The class Apartment :

class Apartment(models.Model):   
_name = 'apartment'   
_description = 'Apartment'   
_sql_constraints = [('unique_name', 'unique(name)', 'An apartment with the same name exist')]
 name = fields.Char(string="Name")   
description = fields.Text(string="Description")   
image = fields.Image(max_height=500, max_width=500, string="Picture")   
available_date = fields.Datetime(string="Available date")   
price = fields.Integer(string="Price")
The class productApartment :
classProductApartment(models.Model):   
    _inherit = 'product.template'
    apartment_product = fields.Many2one('apartment', string="Apartment", ondelete="cascade")


I want to dynamically computes the price of product.template with the price attribute from Apartment


How can I do that ?



Thanks in advance

Avatar
Discard
Author Best Answer

Thanks a lot

Avatar
Discard
Best Answer

Hi,

Try the below code.

class ProductApartment(models.Model):
_inherit = 'product.template'
apartment_product = fields.Many2one('apartment', string="Apartment", ondelete="cascade")

@api.onchange('apartment_product')
def dynamic_pricing(self):
self.list_price = self.apartment_product.price

Regards

Avatar
Discard