This question has been flagged
2 Replies
6658 Views

Hello,

I'd two form view of the same model: 'dieu_chinh.py'. I want to open a specific form view with the code in xml like that:

<record id="giam_tam_thoi_form_view" model="ir.ui.view">

            <field name="name">giam.tam.thoi.form.view</field>

            <field name="model">dieu.chinh</field>

            <field name="arch" type="xml">

                <form string="Temporary Reduce">

                    <group class="oe_title">

                       <field name="name" readonly="1"/>

                    </group>

                    <group class="oe_title">   

                        <field name="thamchieu"/>

                    </group>

                    <group class="oe_title">

                        <field name="thoigian"/>

                    </group>

                    <footer>

                        <button name="giam_tam_thoi_wz" string="CONFIRM" type="object" class="btn-success"/>

                        <button string="CANCEL" class="btn-secondary" special="cancel"/>

                    </footer>

                </form>

            </field>

        </record>


the button in XML:

<button type="object" string="Temporary Reduce" name= "open_popup_form_dc_gtt" 

                                states="dangchay" class="btn-success"/>


And I defined the button with function by python like this:

def open_popup_form_dc_gtt(self):

        return {

            'name': 'Giảm Tạm Thời',

            'view_mode': 'form',

            'res_model': 'dieu.chinh',

            'view_id': self.env.ref('dieuchinh.giam_tam_thoi_form_view').id,

            'context': {'default_name': self.name.id},

            'target': 'new',

            'type': 'ir.actions.act_window',

            }

After click the button, I got the error inform like this:

Odoo Server Error
Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/tools/cache.py", line 85, in lookup
    r = d[key]
  File "/home/odoo/src/odoo/odoo/tools/func.py", line 69, in wrapper
    return func(self, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/tools/lru.py", line 44, in __getitem__
    a = self.d[obj].me
KeyError: ('ir.model.data', <function IrModelData.xmlid_lookup at 0x7f6aa0b24840>, 'dieuchinh.giam_tam_thoi_form_view')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/http.py", line 624, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo/src/odoo/odoo/http.py", line 310, in _handle_exception
    raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
  File "/home/odoo/src/odoo/odoo/tools/pycompat.py", line 14, in reraise
    raise value
  File "/home/odoo/src/odoo/odoo/http.py", line 669, in dispatch
    result = self._call_function(**self.params)
  File "/home/odoo/src/odoo/odoo/http.py", line 350, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/service/model.py", line 94, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/odoo/src/odoo/odoo/http.py", line 339, in checked_call
    result = self.endpoint(*a, **kw)
  File "/home/odoo/src/odoo/odoo/http.py", line 915, in __call__
    return self.method(*args, **kw)
  File "/home/odoo/src/odoo/odoo/http.py", line 515, in response_wrap
    response = f(*args, **kw)
  File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1331, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/home/odoo/src/odoo/addons/web/controllers/main.py", line 1319, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/home/odoo/src/odoo/odoo/api.py", line 387, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/home/odoo/src/odoo/odoo/api.py", line 374, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "/home/odoo/src/odoo/addons/baohiem/models/bao_hiem.py", line 79, in open_popup_form_dc_gtt
    'view_id': self.env.ref('dieuchinh.giam_tam_thoi_form_view').id,
  File "/home/odoo/src/odoo/odoo/api.py", line 501, in ref
    return self['ir.model.data'].xmlid_to_object(xml_id, raise_if_not_found=raise_if_not_found)
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 1701, in xmlid_to_object
    t = self.xmlid_to_res_model_res_id(xmlid, raise_if_not_found)
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 1685, in xmlid_to_res_model_res_id
    return self.xmlid_lookup(xmlid)[1:3]
  File "<decorator-gen-24>", line 2, in xmlid_lookup
  File "/home/odoo/src/odoo/odoo/tools/cache.py", line 90, in lookup
    value = d[key] = self.method(*args, **kwargs)
  File "/home/odoo/src/odoo/odoo/addons/base/models/ir_model.py", line 1674, in xmlid_lookup
    raise ValueError('External ID not found in the system: %s' % xmlid)
ValueError: External ID not found in the system: dieuchinh.giam_tam_thoi_form_view


What am I doing wrong?

Please help!

Thank you!

Avatar
Discard
Best Answer

Your code LGTM.

As per the error, the system is not able to find the "giam_tam_thoi_form_view" view.

Please make sure the view is loaded or the XML file in which the view is defined is added in the manifest py file and then update your module.


Avatar
Discard
Author Best Answer

Hello Sudhir,

Thank you for your support. Yes, I got it!

Avatar
Discard