3

I'm migrating a module from version 15.0 to version 16.0 and I'm getting an error in context due to the group added to the "operation_unit_id" field in the xml and I don't know how to fix it. Can you help me? The field "operation_unit_id" is created in the "purchase.order.line" and in the "purchase.order" template.

<record id="purchase_order_form" model="ir.ui.view">
    <field name="name">purchase_order_form</field>
    <field name="model">purchase.order</field>
    <field name="inherit_id" ref="purchase.purchase_order_form" />
    <field name="arch" type="xml">
        <field name="partner_ref" position="after">
            <field
name="requesting_operating_unit_id"
groups="operating_unit.group_multi_operating_unit"
/>
            <field
name="operating_unit_id"
groups="operating_unit.group_multi_operating_unit"
/>
        </field>
        <field name="order_line" position="attributes">
            <attributename="context">{"default_state": "draft", "default_operating_unit_id": operating_unit_id}</attribute>
        </field>
    </field>
</record>
Traceback (most recent call last):
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1583, in _serve_db
    return service_model.retrying(self._serve_ir_http, self.env)
  File "/opt/odoo/custom/src/odoo/odoo/service/model.py", line 134, in retrying
    result = func()
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1610, in _serve_ir_http
    response = self.dispatcher.dispatch(rule.endpoint, args)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 1807, in dispatch
    result = self.request.registry['ir.http']._dispatch(endpoint)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
    result = endpoint(**request.params)
  File "/opt/odoo/custom/src/odoo/odoo/http.py", line 696, in route_wrapper
    result = endpoint(self, *args, **params_ok)
  File "/opt/odoo/auto/addons/web/controllers/dataset.py", line 46, in call_button
    action = self._call_kw(model, method, args, kwargs)
  File "/opt/odoo/auto/addons/web/controllers/dataset.py", line 33, in _call_kw
    return call_kw(request.env[model], method, args, kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 461, in call_kw
    result = _call_kw_multi(method, model, args, kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/api.py", line 448, in _call_kw_multi
    result = method(recs, *args, **kwargs)
  File "<decorator-gen-75>", line 2, in button_immediate_upgrade
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_module.py", line 76, in check_and_log
    return method(self, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_module.py", line 678, in button_immediate_upgrade
    return self._button_immediate_function(type(self).button_upgrade)
  File "/opt/odoo/custom/src/odoo/odoo/addons/base/models/ir_module.py", line 615, in _button_immediate_function
    registry = modules.registry.Registry.new(self._cr.dbname, update_module=True)
  File "<decorator-gen-14>", line 2, in new
  File "/opt/odoo/custom/src/odoo/odoo/tools/func.py", line 87, in locked
    return func(inst, *args, **kwargs)
  File "/opt/odoo/custom/src/odoo/odoo/modules/registry.py", line 90, in new
    odoo.modules.load_modules(registry, force_demo, status, update_module)
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 483, in load_modules
    processed_modules += load_marked_modules(cr, graph,
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 371, in load_marked_modules
    loaded, processed = load_module_graph(
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 230, in load_module_graph
    load_data(cr, idref, mode, kind='data', package=package)
  File "/opt/odoo/custom/src/odoo/odoo/modules/loading.py", line 71, in load_data
    tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind)
  File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 763, in convert_file
    convert_xml_import(cr, module, fp, idref, mode, noupdate)
  File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 829, in convert_xml_import
    obj.parse(doc.getroot())
  File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 749, in parse
    self._tag_root(de)
  File "/opt/odoo/custom/src/odoo/odoo/tools/convert.py", line 709, in _tag_root
    raise ParseError(msg) from None  # Restart with "--log-handler odoo.tools.convert:DEBUG" for complete traceback
odoo.tools.convert.ParseError: while parsing /opt/odoo/auto/addons/purchase_operating_unit/views/purchase_order_view.xml:16
Error while validating view near:

<form string="Purchase Order" class="o_purchase_order" __validate__="1">
                <header>
                    <button name="action_rfq_send" states="draft" string="Send by Email" type="object" context="{'send_rfq':True}" class="oe_highlight" data-hotkey="g"/>

Field 'operating_unit_id' used in context ({'default_state': 'draft', 'default_operating_unit_id': operating_unit_id}) is restricted to the group(s) operating_unit.group_multi_operating_unit.

View error context:
{'file': '/opt/odoo/auto/addons/purchase_operating_unit/views/purchase_order_view.xml',
 'line': 1,
 'name': 'purchase_order_form',
 'view': ir.ui.view(1036,),
 'view.model': 'purchase.order',
 'view.parent': ir.ui.view(979,),
 'xmlid': 'purchase_order_form'}

If I delete the group it already works, but I can't delete it.

1 Answers1

1

The restriction added in Odoo 16 so you can solve it as below,

You will add the operating_unit_id field twice, First to be visible for the operating_unit.group_multi_operating_unit group :

<field name="operating_unit_id"
       groups="operating_unit.group_multi_operating_unit"
/>

The second one, you will set it invisible for all user not in the operating_unit.group_multi_operating_unit group:

<field name="operating_unit_id" invisible="1"
       groups="!operating_unit.group_multi_operating_unit"/>
</field>

Here you are the complete view XML:

    <record id="purchase_order_form" model="ir.ui.view">
            <field name="name">purchase_order_form</field>
            <field name="model">purchase.order</field>
            <field name="inherit_id" ref="purchase.purchase_order_form"/>
            <field name="arch" type="xml">
                <field name="partner_ref" position="after">
                    <field name="requesting_operating_unit_id"
                           groups="operating_unit.group_multi_operating_unit"
                    />
                    <field
                            name="operating_unit_id"
                            groups="operating_unit.group_multi_operating_unit"
                    />

                    <field name="operating_unit_id" invisible="1"
                           groups="!operating_unit.group_multi_operating_unit"/>
                </field>
                <field name="order_line" position="attributes">
                    <attributename="context">{"default_state": "draft",
                    "default_operating_unit_id": operating_unit_id}
                </attribute>
            </field>
        </field>
    </record>
Waleed Mohsen
  • 965
  • 6
  • 8