在Odoo 8中,我有一个带有函数的计算字段,导致错误。 似乎无法使事情有效并需要一些帮助。
我的测试代码:
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 * 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))
planob_p1 = fields.Float('Plano Breedte P1')
planobt_p1 = fields.Float('Plano Breedte toeslag P1')
val1 = fields.Float(compute = '_functionb_p1', store=True,
string = 'Aanmaak Plano breedte P1',
help = "Berekening vanuit functie _functionb_p1")
ERROR:
File "....8.0\test\models\calc.py", line 47, in _functionb_p1
val1 = calc.hoogte + (2.0 * plano.Kw) + 2.0
TypeError: unsupported operand type(s) for *: 'float' and 'Float'
答案 0 :(得分:0)
TypeError非常奇怪。 Odoo Float从未遇到过这样的问题...
但是一些提示你的计算功能。它应该使用@ api.multi或@ api.one(不推荐使用第二个)作为附加装饰器。
然后你应该在plano和calc模型之间建立联系。您的模型关系(没有人)不允许您正在寻找的计算,因为您需要plano实例/记录和计算实例/记录。
你正在计算你的calc模型的价值,所以我会尝试给你一个正确的方法,有一个条件:在calc模型上有一个名为plano_id的Many2One字段。
@api.multi
@api.depends('name')
def _functionb_p1(self):
for calc in self:
val1 = 0.0
plano = calc.plano_id
if plano.testB_p1 != 'H+':
val1 = calc.hoogte + (2.0 * plano.Kw) + 2.0
elif calc.plano_id.testB_p1 != 'B':
val1 = calc.breedte + (plano.toeslagB_p1 * plano.Kw)
calc.val1 = val1
# my condition!
plano_id = fields.Many2One(comodel_name="plano", string="Plano")