Menu

Trợ giúp

0

Hi Community this is the Coumpute field error help me how i can reslove it

Avatar
Muhammad Haroon khan
Traceback (most recent call last):
  File "/home/khan/odoo-16.0/odoo/api.py", line 984, in get
    cache_value = field_cache[record._ids[0]]
KeyError: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/khan/odoo-16.0/odoo/fields.py", line 1160, in __get__
    value = env.cache.get(record, self)
  File "/home/khan/odoo-16.0/odoo/api.py", line 991, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'practice.module(,).total_books'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/khan/odoo-16.0/odoo/api.py", line 984, in get
    cache_value = field_cache[record._ids[0]]
KeyError: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/khan/odoo-16.0/odoo/fields.py", line 1213, in __get__
    value = env.cache.get(record, self)
  File "/home/khan/odoo-16.0/odoo/api.py", line 991, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: 'practice.module(,).total_books'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/khan/odoo-16.0/odoo/http.py", line 1584, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/home/khan/odoo-16.0/odoo/service/model.py", line 133, in retrying
    result = func()
  File "/home/khan/odoo-16.0/odoo/http.py", line 1611, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/home/khan/odoo-16.0/odoo/http.py", line 1815, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/home/khan/odoo-16.0/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
  File "/home/khan/odoo-16.0/odoo/http.py", line 697, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/home/khan/odoo-16.0/addons/web/controllers/dataset.py", line 42, in call_kw
    return self._call_kw(model, method, args, kwargs)
  File "/home/khan/odoo-16.0/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/khan/odoo-16.0/odoo/api.py", line 461, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/khan/odoo-16.0/odoo/api.py", line 448, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/khan/odoo-16.0/odoo/models.py", line 6524, in onchange
    snapshot1 = Snapshot(record, nametree)
  File "/home/khan/odoo-16.0/odoo/models.py", line 6284, in __init__
    self.fetch(name)
  File "/home/khan/odoo-16.0/odoo/models.py", line 6294, in fetch
    self[name] = record[name]
  File "/home/khan/odoo-16.0/odoo/models.py", line 5876, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "/home/khan/odoo-16.0/odoo/fields.py", line 1216, in __get__
    raise ValueError("Compute method failed to assign %s.%s" % (record, self.name))
ValueError: Compute method failed to assign practice.module(,).total_books

The above server error caused the following client error:
null


3 Bình luận
Ảnh đại diện
Huỷ bỏ
Avatar
Savya Sachin
-

Kindly paste your compute method also for better understanding

Avatar
Muhammad Haroon khan
-
class PracticeModule(models.Model):
_name = 'practice.module'
_description = 'practice_module.practice_module'

name = fields.Char(string="Name")
age = fields.Integer(string="Age")
std_class = fields.Integer(string="Class")
address = fields.Char(string="Address")
total_books = fields.Integer(string="Total books", compute='_class_vise_books')
country = fields.Many2one(comodel_name='res.country', String='Country')

@api.depends('std_class')
def _class_vise_books(self):
for record in self:
if record.std_class == 1:
record.total_books += 4
elif
record.std_class == 2:
record.total_books += 5
elif
record.std_class == 3:
record.total_books += 6
elif
record.std_class == 4:
record.total_books += 6
elif
record.std_class == 5:
record.total_books += 7


Avatar
Muhammad Haroon khan
-

Thank you your code is working 

1 Trả lời
1
<span class="o_forum_tooltip_line">https://www.linkedin.com/in/savyasachin/</span> </a> </div> <b class="mt-4"><i class="fa fa-diamond text-secondary"></i> 20950</b> <div style="display: inline-block"> <b>|</b> <span class="fa fa-trophy bg-gold ms-2" role="img" aria-label="Gold badge" title="Gold badge"></span> 7 <span class="fa fa-trophy bg-silver ms-2" role="img" aria-label="Silver badge" title="Silver badge"></span> 4 <span class="fa fa-trophy bg-bronze ms-2" role="img" aria-label="Bronze badge" title="Bronze badge"></span> 10 </div> <div class="mt-2"> <div class="o_forum_tooltip_line"> <span>Kozhikode</span><span>, </span><span>Ấn-độ</span> </div> </div> </div> </div> </address></span> <div class="o_wforum_bio_popover_bio" data-oe-type="contact" data-oe-expression="user"> <address class="mb-0" itemscope="itemscope" itemtype="http://schema.org/Organization"> <div class="css_non_editable_mode_hidden"> --<span class="text-muted">Savya Sachin </span>-- </div> <div itemprop="address" itemscope="itemscope" itemtype="http://schema.org/PostalAddress"> </div> <div> <span> <span><p><strong>Odoo Techno Functional Consultant</strong> </p><p><strong>Email</strong>: <a href=https://www.odoo.com/vi_VN/forum/tro-giup-1/"mailto:theodoobin@gmail.com" rel="ugc">theodoobin@gmail.com</a></p><p><strong>Skype: <a href=https://www.odoo.com/vi_VN/forum/tro-giup-1/"https://join.skype.com/invite/IYifcC2nQo03" rel="ugc" target="_blank">theodoobin@gmail.com</a></strong></p><p><b>LinkedIn:</b> <a href=https://www.odoo.com/vi_VN/forum/tro-giup-1/"https://www.linkedin.com/in/savya-sachin-t-ba8167a9/" target="_blank" rel="ugc">https://www.linkedin.com/in/savya_sachin/</a><br></p><p><br></p><pre><br><br> </pre><pre> </pre></span> </span> </div> </address></div> </div> </div> "> Avatar
Savya Sachin
Best Answer

Hi,

Kindly replace you code like this and try,

@api.depends('std_class')
def _class_vise_books(self):
for record in self:
if record.std_class:
if record.std_class == 1:
record.total_books += 4
elif record.std_class == 2:
record.total_books += 5
elif record.std_class == 3:
record.total_books += 6
elif record.std_class == 4:
record.total_books += 6
elif record.std_class == 5:
record.total_books += 7
else:
record.total_books = 0
else:
record.total_books = 0

Thanks

Ảnh đại diện
Huỷ bỏ