콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
13014 화면

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)

아바타
취소
베스트 답변

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
아바타
취소
작성자

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

관련 게시물 답글 화면 활동
2
6월 25
1793
1
12월 24
2436
3
4월 24
3662
1
1월 25
5952
0
10월 23
1293