Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
2 Відповіді
997 Переглядів

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

Аватар
Відмінити
Автор Найкраща відповідь

Thanks a lot

Аватар
Відмінити
Найкраща відповідь

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

Аватар
Відмінити