تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
1997 أدوات العرض

Hello, 

I need to calculate a fiel depending on the value in another related field that is already in the model.


I am trying with this, but i get and error.


for record in self:
if record.x_studio_categoria_producto_1 == 'Factor 96':
record['x_studio_calculo_precio'] = record.standard_price * 1.96
if record.x_studio_categoria_producto_1 == 'Factor 88':
record['x_studio_calculo_precio'] = record.standard_price * 1.88


I would preciate if you help me 

الصورة الرمزية
إهمال

i think you should give this ""record['x_studio_calculo_precio']"" as record.x_studio_calculo_precio

أفضل إجابة

Hello Dear

It will be helpful if you add the error message so we can help you.

Meanwhile, I'm going to assume that you used the same code exactly and the error is in the Indentation which is the space before the code.  Python uses indentation to indicate a block of code.  So if you add the indent the code will look like this:

for record in self:
     if record.x_studio_categoria_producto_1 == 'Factor 96':
        record['x_studio_calculo_precio'] = record.standard_price * 1.96      if record.x_studio_categoria_producto_1 == 'Factor 88':
        record['x_studio_calculo_precio'] = record.standard_price * 1.88 


instead of this

for record in self:
if record.x_studio_categoria_producto_1 == 'Factor 96':
record['x_studio_calculo_precio'] = record.standard_price * 1.96     if record.x_studio_categoria_producto_1 == 'Factor 88': record['x_studio_calculo_precio'] = record.standard_price * 1.88 
الصورة الرمزية
إهمال