I am working a Demo through QWEB on my own instance in docker. Trying to make a Area Calculation for products. It is kindly of simple but variable. The goal is to show the Area with unit which the user select. Here is the calculation:
Width * Height / Ratio of Length ^2 = Area * Ratio of Area
Reference Unit of Length is meter, and reference Unit of Area is M2; The other units are set correctly and tested the ratio.
Float Fields: x_width, x_height, x_area
Many2One Fields: x_size_uom, x_area_uom
Object Relation: product.uom
Domain: [('category_id.name', '=', 'Length/ Distance')] & [('category_id.name', '=', 'Area')]
This is what I have set for field x_area:
Dependencies: x_width, x_height, x_size_uom, x_area_uom (4 related fields above)
Compute:
for record in self:
record[('x_area')] = record.x_width * record.x_height / (record.x_size_uom.factor * record.x_size_uom.factor) * record.x_area_uom.factorIt is working and calculated correctly, no matter what unit of length is calculated but also error popup, listed as below:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 944, in __get__
value = record.env.cache.get(record, self)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 960, in get
value = self._data[field][record.id][key]
KeyError: <odoo.api.Environment object at 0x7f295009bb70>
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 348, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 2, in <module>
ZeroDivisionError: float division by zero
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/odoo/http.py", line 646, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 307, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 87, in reraise
raise value
File "/usr/lib/python3/dist-packages/odoo/http.py", line 683, in dispatch
result = self._call_function(**self.params)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 332, in checked_call
result = self.endpoint(*a, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 927, in __call__
return self.method(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/http.py", line 512, in response_wrap
response = f(*args, **kw)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 920, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 912, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 689, in call_kw
return call_kw_multi(method, model, args, kwargs)
File "/usr/lib/python3/dist-packages/odoo/api.py", line 680, in call_kw_multi
result = method(recs, *args, **kwargs)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4966, in onchange
record.mapped(dotname)
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4414, in mapped
recs = recs._mapped_func(operator.itemgetter(name))
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4393, in _mapped_func
vals = [func(rec) for rec in self]
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4393, in <listcomp>
vals = [func(rec) for rec in self]
File "/usr/lib/python3/dist-packages/odoo/models.py", line 4660, in __getitem__
return self._fields[key].__get__(self, type(self))
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 948, in __get__
self.determine_value(record)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1059, in determine_value
self.compute_value(recs)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1015, in compute_value
self._compute_value(records)
File "/usr/lib/python3/dist-packages/odoo/fields.py", line 1008, in _compute_value
self.compute(records)
File "/usr/lib/python3/dist-packages/odoo/addons/base/ir/ir_model.py", line 30, in <lambda>
func = lambda self: safe_eval(text, SAFE_EVAL_BASE, {'self': self}, mode="exec")
File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 371, in safe_eval
pycompat.reraise(ValueError, ValueError('%s: "%s" while evaluating\n%r' % (ustr(type(e)), ustr(e), expr)), exc_info[2])
File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 86, in reraise
raise value.with_traceback(tb)
File "/usr/lib/python3/dist-packages/odoo/tools/safe_eval.py", line 348, in safe_eval
return unsafe_eval(c, globals_dict, locals_dict)
File "", line 2, in <module>
ValueError: <class 'ZeroDivisionError'>: "float division by zero" while evaluating
"for record in self:\n record[('x_area')] = record.x_width * record.x_height / (record.x_size_uom.factor * record.x_size_uom.factor) * record.x_area_uom.factor"I have no ideas how the float divided by zero
This is how I insert into a view:
<label for="x_area" string="Area"/>
<div>
<field name="x_width" class="oe_inline"/> x <field name="x_height" class="oe_inline"/>
<field name="x_size_uom" class="oe_inline oe_no_button"/> = <br/>
<field name="x_area" class="oe_inline"/><field name="x_area_uom" class="oe_inline oe_no_button"/>
</div>