Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Calculating fields from two new Odoo 8 classes result in error.

By
R.Wouters
on 10/30/15, 4:35 AM 437 views

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")

0

zbik

--zbik--
5941
| 6 4 7
Lodz, Poland
--zbik--


zbik
On 10/30/15, 5:43 AM

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)

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/30/15, 4:35 AM
Seen: 437 times
Last updated: 10/30/15, 5:43 AM