This question has been flagged

Hello. 


I am creating a custom module, I have installed my module fine on Odoo 12 and I have added actions and menuitems for my module however, when I click the menu I keep getting an error and I am unsure of how to narrow down where the error is coming from.

ERROR WHEN CLICKIN ON THE MENU:

Error:
Odoo Server Error
Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\api.py", line 1049, in get
    value = self._data[key][field][record._ids[0]]
KeyError: 133
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1012, in __get__
    value = record.env.cache.get(record, self)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\api.py", line 1051, in get
    raise CacheMiss(record, field)
odoo.exceptions.CacheMiss: ('ir.actions.act_window(133,).search_view', None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 656, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 314, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\tools\pycompat.py", line 87, in reraise
    raise value
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 698, in dispatch
    result = self._call_function(**self.params)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 346, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\service\model.py", line 98, in wrapper
    return f(dbname, *args, **kwargs)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 941, in __call__
    return self.method(*args, **kw)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\http.py", line 519, in response_wrap
    response = f(*args, **kw)
  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\web\controllers\main.py", line 1262, in load
    action = request.env[action_type].browse([action_id]).read()
  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 210, in read
    result = super(IrActionsActWindow, self).read(fields, load=load)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 2820, in read
    vals[name] = convert(record[name], record, use_name_get)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 5148, in __getitem__
    return self._fields[key].__get__(self, type(self))
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1016, in __get__
    self.determine_value(record)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1129, in determine_value
    self.compute_value(recs)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1083, in compute_value
    self._compute_value(records)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1074, in _compute_value
    getattr(records, self.compute)()
  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_actions.py", line 170, in _compute_search_view
    fvg = self.env[act.res_model].fields_view_get(act.search_view_id.id, 'search')
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 1482, in fields_view_get
    xarch, xfields = View.postprocess_and_fields(self._name, etree.fromstring(result['arch']), view_id)
  File "c:\program files (x86)\odoo 12.0\server\odoo\addons\base\models\ir_ui_view.py", line 1110, in postprocess_and_fields
    fields = Model.fields_get(None)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\models.py", line 2713, in fields_get
    description = field.get_description(self.env)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 770, in get_description
    value = value(env)
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1985, in _description_selection
    return [(value, translate(label) if label else label) for value, label in selection]
  File "C:\Program Files (x86)\Odoo 12.0\server\odoo\fields.py", line 1985, in <listcomp>
    return [(value, translate(label) if label else label) for value, label in selection]
ValueError: too many values to unpack (expected 2)

My XML:

<record model="ir.ui.view" id="alumnos_fp_tree">
      <field name="name">alumnos.fp.tree</field>
      <field name="model">alumnos.fp</field>
      <field name="arch" type="xml">
        <tree>
          <field name="nombre"/>
          <field name="apellidos"/>
          <field name="fecha"/>
          <field name="ciclo"/>
          <field name="nota"/>
        </tree>
        </field>
    </record>

    <record model="ir.ui.view" id="alumnos_fp_form">
      <field name="name">alumnos.fp.form</field>
      <field name="model">alumnos.fp</field>
      <field name="arch" type="xml">
        <form>
        <group colspan="2" col="2">
            <field name="nombre"/>
            <field name="apellidos"/>
            <field name="fecha"/>
            <field name="ciclo"/>
            <field name="nota"/>
          </group>
        </form>
      </field>
    </record>

    <record model="ir.ui.view" id="alumnos_practicas_tree">
      <field name="name">alumnos.practicas.tree</field>
      <field name="model">alumnos.practicas</field>
      <field name="arch" type="xml">
        <tree>
          <field name="nombre"/>
          <field name="direccion"/>
        </tree>
        </field>
    </record>

    <record model="ir.ui.view" id="alumnos_practicas_form">
      <field name="name">alumnos.practicas.form</field>
      <field name="model">alumnos.practicas</field>
      <field name="arch" type="xml">
        <form>
        <group colspan="2" col="2">
            <field name="nombre"/>
            <field name="direccion"/>
          </group>
        </form>
      </field>
    </record>

    <record model="ir.actions.act_window" id="alumnos_fp_action_window">
      <field name="name">Alumnos.fp.action_window</field>
      <field name="res_model">alumnos.fp</field>
      <field name="view_mode">tree,form</field>
    </record>

     <record model="ir.actions.act_window" id="alumnos_practicas_action_window">
      <field name="name">Alumnos.practicas.action_window</field>
      <field name="res_model">alumnos.practicas</field>
      <field name="view_mode">tree, form</field>
    </record>

    <menuitem name="Alumnos" id="alumnos_menu_root"/>

    <menuitem name="Alumnos FP" id="alumnos_fp_menu" parent="alumnos_menu_root" action="alumnos_fp_action_window"/>
    <menuitem name="Practicas" id="alumnos_practicas_menu" parent="alumnos_menu_root" action="alumnos_practicas_action_window"/>

I have checked the views, models and actions in Odoo and it seems they are all created.
Avatar
Discard

Hello Paul,

I can see an error in the code but am unsure whether this produces that error code in V12.

The error I see is the space in "tree, form" for the view_mode of the "alumnos_practicas_action_window" window action.

If this isn't the case, I think there may be an error with a selection field on one of the Python models. Is there any chance you could share the Python code?

Thanks,

Author Best Answer

Hi, Thanks for your help. As suggested Jack, I decided to remove a few fields from model.py and when I remove these three:

    fecha = fields.Date(string="Fecha de nacimiento", help="Elegir tu fecha de nacimiento")
    ciclo = fields.Selection([('DAM'),('DAW'),('ASIR')], string="Ciclo Formativo",default="0")
    nota = fields.Float(string="Nota", help="Introducir tu nota")

The menus load fine, so somewhere in these fields is the error. 


EDIT: Narrowing it down further is seems it was my fields.Selection that was causing the error, if I remove the field it loads. Not sure what the error is though.


EDIT AGAIN: Looks like it is because I wasn't putting the indexes in the selection field. I'm giving it a try now.


SOLUTION: That was the error, I hadn't put the indexes in. Because the error was only shown when I added the actions I was convinced it was the action that was wrong.


Thanks a lot for you help.

Avatar
Discard

Glad you managed to solve this