Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
12560 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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

Gerelateerde posts Antwoorden Weergaven Activiteit
1
dec. 24
1545
1
aug. 24
1006
3
apr. 24
2368
1
jan. 25
5491
0
okt. 23
792