我的主数据模型包含很多项目,我在product.template中将其称为
我需要您帮助我,如何仅在我打开产品表单并选择其汽车记录后才根据self.factor和self.standard_price(在产品表单上)自己计算出字段,suggested_price才能得到它的值>
我在主数据模型上创建了两个字段(因子,suggeted_price) 我将系数设为Float,以百分比表示,suggested_price的计算字段等于(系数* 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
name = fields.Char( string="Car",translate=True , required=True, ondelete='restrict')
int_ref = fields.Char(string="Internal reference", required=False,store=True )
model = fields.One2many(comodel_name="models", inverse_name="car", string="Models", required=False, ondelete='restrict', )
pro = fields.Char(string="profit mergin", required=False, type='int')
year = fields.Many2one(comodel_name="yearrange", string="", required=False,domain="[('name','=', car )]" )
factor = fields.Float(string="", required=False, )
suggeted_price = fields.Float(string="", required=False, compute=car_price )
class autopart(models.Model):
_inherit = 'product.template'
car = fields.Many2many(comodel_name="cars", string="", )
我得到错误的“汽车”对象没有属性“产品”,这正是我所期望的