Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
12938 Ansichten

i have master data model contains a lot of items and i called it in product.template 
i need to make tow fields on master data model (factor, suggeted_price)
i make the factor is Float as percentage and suggested_price is computed field that equal (factor * product.template.standard_price)

    class cars(models.Model):
_name = 'cars'

@api.one
@api.depends('factor',)
def car_price(self):
if self.factor:
self.suggeted_price = self.factor * self.product.template.standard_price
pass

factor = fields.Float(string="", required=False, )
suggeted_price = fields.Float(string="", required=False, compute=car_price )

i get error  'cars' object has no attribute 'product' that's actually what i expected 
i need from you to help me on how make the computed field suggested_price get it's value only when i open product form and chose it's car record then calculate itself from self.factor and self.standard_price(which on product form)

Avatar
Verwerfen
Beste Antwort

Hi Mohamed,

For getting the details of the product you have to inherit product_template model, then you can compute the value of suggested price with standard_price field in product_template as follows 

class cars(models.Model):
 _name = 'cars'
_inherit = “product.template”

factor = fields.Float(string="",  required=False, )
suggeted_price = fields.Float(string="",  required=False, compute=car_price )

@api.one
@api.depends('factor')
def car_price(self):
if self.factor:
self.suggeted_price = self.factor * self.standard_price
        return
Avatar
Verwerfen
Autor

thank you for your internist, i'am already inherit product.template and add a many2many field from model above called car and it's view like a tree in product form contains some of column (.,.,., factor,suggested_price) i need when i select a car fill all column with their values and suggested price get it's value from factor's column * self.standard_price

Verknüpfte Beiträge Antworten Ansichten Aktivität
2
Juni 25
1743
1
Dez. 24
2310
3
Apr. 24
3579
1
Jan. 25
5860
0
Okt. 23
1192