Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
12458 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
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

Related Posts Odpovědi Zobrazení Aktivita
1
pro 24
1392
1
srp 24
873
3
dub 24
2177
1
led 25
5397
0
říj 23
668