Skip to Content
Menu
This question has been flagged

Class ' Plano' contains static reference variables/values, where class 'Calc' should calculate with these values. But whenever I change any 'triggerfields' like defined in 'api.depends', there is an error like: 

File "E:/MRP/odoo-8.0-8/apps/odoo/data\addons\8.0\test\models\calc.py", line 47, in _functionb_p1

val1 = calc.hoogte + (2.0 * float(plano.Kw)) + 2.0

TypeError: unsupported operand type(s) for +: 'Float' and 'int'

Source example:

from openerp import models, fields, api, _
from openerp.tools.translate import _
import openerp.addons.decimal_precision as dp

class plano(models.Model):
_name = 'plano'
_description = "variabelen plaat toeslagen, rillen kenmerken."

name = fields.Char('Plano naam', required=True)
constructie_id = fields.Char('Fefco constructie')
testB_p1 = fields.Char('Breedte P1', help = 'Tekst veld P1 (variabele breedte P1)')
toeslagB_p1 = fields.Float('toeslag breedte P1 (variabel Breedte P1)', digits=(3, 1))
testL_p1 = fields.Char('Lengte P1', help = 'Tekst veld P1 (variabele lengte P1)')
toeslagL_p1 = fields.Float('toeslag lengte P1 (variabel lengte P1)', digits=(3, 1))
Kw = fields.Float('Kwaliteit dikte in mm', digits=(3, 0), help = "Wordt uit gerelateerd veld van model Quality gehaald.")


class calc(models.Model):

@api.depends('name')
def _functionb_p1(self):
val1 = 0.0

if plano.testB_p1 != 'H+':
val1 = calc.hoogte + (2.0 * float(plano.Kw)) + 2.0
elif plano.testB_p1 != 'B':
val1 = calc.breedte + (plano.toeslagB_p1 * plano.Kw)
return val1

_name = "calc"
_description = "kostprijs berekening."

name = fields.Many2one('plano', help = "Kostprijs berekening nummer e.g. C1234")
lengte = fields.Float('Lengte in mm', digits=(4, 0), help = "Lengte in mm")
breedte = fields.Float('Breedte in mm', digits=(4, 0))
hoogte = fields.Float('Hoogte in mm', digits=(4, 0))
aantal = fields.Float('Aantal stuks', digits=(4, 0))
 
val1 = fields.Float(compute = '_functionb_p1', store=True,
string = 'Aanmaak Plano breedte P1',
help = "Berekening vanuit functie _functionb_p1")

Avatar
Discard
Best Answer

Do not use the names of calc and plano directly, instead of them use self and self.name, like this:

if self.name.testB_p1 != 'H+':
    self.val1 = self.hoogte + (2.0 * float(self.name.Kw)) + 2.0
elif self.name.testB_p1 != 'B':
   self.val1 = self.breedte + (self.name.toeslagB_p1 * self.name.Kw)

Avatar
Discard
Related Posts Replies Views Activity
2
Mar 24
475
2
Jul 21
15457
2
Nov 19
5462
1
May 17
2398
3
May 24
433