Skip to Content
Menu
This question has been flagged
2 Replies
25321 Views

Error is as followed: My current setup is this. I am using the technical names of the labels of the floats for referencing them. 

My dependencies are : standard_price, list_price

My compute field is

from odoo import api
total = fields.Float(compute='_compute_total')

@api.depends('standard_price', 'list_price')
def _compute_total(self):
    for record in self:
        record.total = record.standard_price + record.standard_price * record.list_price

My error in Oddo inventory. What am i missing? Im trying to add two floats together . This test is on the online trial version with developer mode enabled 

Error:

Odoo Server Error


Traceback (most recent call last):

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 1032, in get

    value = self._data[field][record.id][key]

KeyError: <odoo.api.Environment object at 0x7fcf2f6ac898>


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 970, in __get__

    value = record.env.cache.get(record, self)

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 1034, in get

    raise CacheMiss(record, field)

odoo.exceptions.CacheMiss: ('product.template(<odoo.models.NewId object at 0x7fcf2f6a0948>,).x_studio_field_P2wHx', None)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 653, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 312, in _handle_exception

    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

  File "/home/odoo/src/odoo/12.0/odoo/tools/pycompat.py", line 87, in reraise

    raise value

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 695, in dispatch

    result = self._call_function(**self.params)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 344, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/service/model.py", line 97, in wrapper

    return f(dbname, *args, **kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 337, in checked_call

    result = self.endpoint(*a, **kw)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 938, in __call__

    return self.method(*args, **kw)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 517, in response_wrap

    response = f(*args, **kw)

  File "/home/odoo/src/odoo/12.0/addons/web/controllers/main.py", line 962, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "/home/odoo/src/odoo/12.0/addons/web/controllers/main.py", line 954, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 749, in call_kw

    return _call_kw_multi(method, model, args, kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 736, in _call_kw_multi

    result = method(recs, *args, **kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/models.py", line 5428, in onchange

    snapshot1 = Snapshot(record, nametree)

  File "/home/odoo/src/odoo/12.0/odoo/models.py", line 5338, in __init__

    if subnames else record[name]

  File "/home/odoo/src/odoo/12.0/odoo/models.py", line 5047, in __getitem__

    return self._fields[key].__get__(self, type(self))

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 976, in __get__

    self.determine_draft_value(record)

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 1096, in determine_draft_value

    self._compute_value(record)

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 1034, in _compute_value

    self.compute(records)

  File "/home/odoo/src/odoo/12.0/odoo/addons/base/models/ir_model.py", line 30, in <lambda>

    func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")

  File "/home/odoo/src/odoo/12.0/odoo/tools/safe_eval.py", line 348, in safe_eval

    c = test_expr(expr, _SAFE_OPCODES, mode=mode)

  File "/home/odoo/src/odoo/12.0/odoo/tools/safe_eval.py", line 213, in test_expr

    assert_valid_codeobj(allowed_codes, code_obj, expr)

  File "/home/odoo/src/odoo/12.0/odoo/tools/safe_eval.py", line 189, in assert_valid_codeobj

    raise ValueError("forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in codes)))

ValueError: forbidden opcode(s) in "from odoo import api\r\ntotal = fields.Float(compute='_compute_total')\r\n\r\n@api.depends('standard_price', 'list_price')\r\ndef _compute_total(self):\r\n    for record in self:\r\n        record.total = record.standard_price + record.standard_price * record.list_price": IMPORT_NAME, IMPORT_FROM

Avatar
Discard
Author Best Answer

Gives me the following error


Error:

Odoo Server Error


Traceback (most recent call last):

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 1032, in get

    value = self._data[field][record.id][key]

KeyError: <odoo.api.Environment object at 0x7f9e1954f1d0>


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 970, in __get__

    value = record.env.cache.get(record, self)

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 1034, in get

    raise CacheMiss(record, field)

odoo.exceptions.CacheMiss: ('product.template(<odoo.models.NewId object at 0x7f9e077ab7c8>,).x_studio_field_CKrxZ', None)


During handling of the above exception, another exception occurred:


Traceback (most recent call last):

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 653, in _handle_exception

    return super(JsonRequest, self)._handle_exception(exception)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 312, in _handle_exception

    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

  File "/home/odoo/src/odoo/12.0/odoo/tools/pycompat.py", line 87, in reraise

    raise value

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 695, in dispatch

    result = self._call_function(**self.params)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 344, in _call_function

    return checked_call(self.db, *args, **kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/service/model.py", line 97, in wrapper

    return f(dbname, *args, **kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 337, in checked_call

    result = self.endpoint(*a, **kw)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 938, in __call__

    return self.method(*args, **kw)

  File "/home/odoo/src/odoo/12.0/odoo/http.py", line 517, in response_wrap

    response = f(*args, **kw)

  File "/home/odoo/src/odoo/12.0/addons/web/controllers/main.py", line 962, in call_kw

    return self._call_kw(model, method, args, kwargs)

  File "/home/odoo/src/odoo/12.0/addons/web/controllers/main.py", line 954, in _call_kw

    return call_kw(request.env[model], method, args, kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 749, in call_kw

    return _call_kw_multi(method, model, args, kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/api.py", line 736, in _call_kw_multi

    result = method(recs, *args, **kwargs)

  File "/home/odoo/src/odoo/12.0/odoo/models.py", line 5428, in onchange

    snapshot1 = Snapshot(record, nametree)

  File "/home/odoo/src/odoo/12.0/odoo/models.py", line 5338, in __init__

    if subnames else record[name]

  File "/home/odoo/src/odoo/12.0/odoo/models.py", line 5047, in __getitem__

    return self._fields[key].__get__(self, type(self))

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 976, in __get__

    self.determine_draft_value(record)

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 1096, in determine_draft_value

    self._compute_value(record)

  File "/home/odoo/src/odoo/12.0/odoo/fields.py", line 1034, in _compute_value

    self.compute(records)

  File "/home/odoo/src/odoo/12.0/odoo/addons/base/models/ir_model.py", line 30, in <lambda>

    func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")

  File "/home/odoo/src/odoo/12.0/odoo/tools/safe_eval.py", line 348, in safe_eval

    c = test_expr(expr, _SAFE_OPCODES, mode=mode)

  File "/home/odoo/src/odoo/12.0/odoo/tools/safe_eval.py", line 213, in test_expr

    assert_valid_codeobj(allowed_codes, code_obj, expr)

  File "/home/odoo/src/odoo/12.0/odoo/tools/safe_eval.py", line 189, in assert_valid_codeobj

    raise ValueError("forbidden opcode(s) in %r: %s" % (expr, ', '.join(opname[x] for x in codes)))

ValueError: forbidden opcode(s) in "from odoo import api\r\ntotal = fields.Float(compute='_compute_total')\r\n\r\n@api.depends('standard_price', 'list_price')\r\ndef _compute_total(self):\r\n    for record in self:\r\n\t      total_amount = record.standard_price + record.standard_price * record.list_price\r\n    self.total =  total_amount": IMPORT_NAME, IMPORT_FROM

Avatar
Discard
Best Answer

Try this

from odoo import api
total = fields.Float(compute='_compute_total')

@api.depends('standard_price', 'list_price')
def _compute_total(self):
for record in self:
total_amount = record.standard_price + record.standard_price * record.list_price
self.total = total_amount



Avatar
Discard