Skip to Content
Menu
This question has been flagged
1 Reply
11736 Views

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
Discard
Best Answer

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
Discard
Author

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 Replies Views Activity
1
Aug 24
228
3
Apr 24
881
0
Dec 23
630
1
Oct 23
4886
0
Oct 23
381