Skip to Content
Menu
This question has been flagged

Hi! I wasted 4 hours searching and yet can not find a good solution. In nightly build 31.03 every user could see all unavailabilities in Time Off\Everyone. After I upgraded the module to the May version, one record rule for some reason has been simply updated. I have found how to fix it manually but to make sure this never happens again, I wrote a small add-on. However, the same technique I saw in the original source code, does not work for my custom code!

I am trying to override the record rule:

    <record id="hr_leave_rule_employee" model="ir.rule">
        <field name="name">Time Off base.group_user read</field>
        <field name="model_id" ref="hr_holidays.model_hr_leave"/>
        <field name="domain_force">[(1,'=',1)]</field>
        <field name="perm_create" eval="False"/>
        <field name="perm_write" eval="False"/>
        <field name="perm_unlink" eval="False"/>
        <field name="groups" eval="[(4,ref('base.group_user'))]"/>
    </record>
and I tried a variety of the model ref samples, but none of them work, and only one

 is definitely wrong, but worked out and strangely created an additional rule with the reference to Qweb Field, while the proper value
hr_holidays.model_hr_leave

throws the following error message:

Error: Odoo Server Error Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 712, in parse self._tag_root(de) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 674, in _tag_root f(rec) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 577, in _tag_record record = model._load_records([data], self.mode == 'update') File "/usr/lib/python3/dist-packages/odoo/models.py", line 4080, in _load_records records = self._load_records_create([data['values'] for data in to_create]) File "/usr/lib/python3/dist-packages/odoo/models.py", line 3994, in _load_records_create return self.create(values) File "<decorator-gen-51>", line 2, in create File "/usr/lib/python3/dist-packages/odoo/api.py", line 336, in _model_create_multi return create(self, arg) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_rule.py", line 199, in create res = super(IrRule, self).create(vals_list) File "<decorator-gen-3>", line 2, in create File "/usr/lib/python3/dist-packages/odoo/api.py", line 336, in _model_create_multi return create(self, arg) File "/usr/lib/python3/dist-packages/odoo/models.py", line 3742, in create records = self._create(data_list) File "/usr/lib/python3/dist-packages/odoo/models.py", line 3895, in _create records._validate_fields(name for data in data_list for name in data['stored']) File "/usr/lib/python3/dist-packages/odoo/models.py", line 1176, in _validate_fields check(self) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_rule.py", line 67, in _check_model_transience if any(self.env[rule.model_id.model].is_transient() for rule in self): File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_rule.py", line 67, in <genexpr> if any(self.env[rule.model_id.model].is_transient() for rule in self): File "/usr/lib/python3/dist-packages/odoo/api.py", line 463, in __getitem__ return self.registry[model_name]._browse(self, (), ()) File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 177, in __getitem__ return self.models[model_name] KeyError: 'hr.leave' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/odoo/http.py", line 624, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/usr/lib/python3/dist-packages/odoo/http.py", line 310, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 14, in reraise raise value File "/usr/lib/python3/dist-packages/odoo/http.py", line 669, in dispatch result = self._call_function(**self.params) File "/usr/lib/python3/dist-packages/odoo/http.py", line 350, in _call_function return checked_call(self.db, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/service/model.py", line 94, in wrapper return f(dbname, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 915, in __call__ return self.method(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/http.py", line 515, in response_wrap response = f(*args, **kw) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1326, in call_button action = self._call_kw(model, method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/web/controllers/main.py", line 1314, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 387, in call_kw result = _call_kw_multi(method, model, args, kwargs) File "/usr/lib/python3/dist-packages/odoo/api.py", line 374, in _call_kw_multi result = method(recs, *args, **kwargs) File "<decorator-gen-66>", line 2, in button_immediate_upgrade File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 72, in check_and_log return method(self, *args, **kwargs) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 634, in button_immediate_upgrade return self._button_immediate_function(type(self).button_upgrade) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_module.py", line 573, in _button_immediate_function modules.registry.Registry.new(self._cr.dbname, update_module=True) File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 86, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 419, in load_modules force, status, report, loaded_modules, update_module, models_to_check) File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 315, in load_marked_modules perform_checks=perform_checks, models_to_check=models_to_check File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 225, in load_module_graph load_data(cr, idref, mode, kind='data', package=package, report=report) File "/usr/lib/python3/dist-packages/odoo/modules/loading.py", line 68, in load_data tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 736, in convert_file convert_xml_import(cr, module, fp, idref, mode, noupdate, report) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 803, in convert_xml_import obj.parse(doc.getroot()) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 721, in parse exc_info[2] File "/usr/lib/python3/dist-packages/odoo/tools/pycompat.py", line 13, in reraise raise value.with_traceback(tb) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 712, in parse self._tag_root(de) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 674, in _tag_root f(rec) File "/usr/lib/python3/dist-packages/odoo/tools/convert.py", line 577, in _tag_record record = model._load_records([data], self.mode == 'update') File "/usr/lib/python3/dist-packages/odoo/models.py", line 4080, in _load_records records = self._load_records_create([data['values'] for data in to_create]) File "/usr/lib/python3/dist-packages/odoo/models.py", line 3994, in _load_records_create return self.create(values) File "<decorator-gen-51>", line 2, in create File "/usr/lib/python3/dist-packages/odoo/api.py", line 336, in _model_create_multi return create(self, arg) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_rule.py", line 199, in create res = super(IrRule, self).create(vals_list) File "<decorator-gen-3>", line 2, in create File "/usr/lib/python3/dist-packages/odoo/api.py", line 336, in _model_create_multi return create(self, arg) File "/usr/lib/python3/dist-packages/odoo/models.py", line 3742, in create records = self._create(data_list) File "/usr/lib/python3/dist-packages/odoo/models.py", line 3895, in _create records._validate_fields(name for data in data_list for name in data['stored']) File "/usr/lib/python3/dist-packages/odoo/models.py", line 1176, in _validate_fields check(self) File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_rule.py", line 67, in _check_model_transience if any(self.env[rule.model_id.model].is_transient() for rule in self): File "/usr/lib/python3/dist-packages/odoo/addons/base/models/ir_rule.py", line 67, in <genexpr> if any(self.env[rule.model_id.model].is_transient() for rule in self): File "/usr/lib/python3/dist-packages/odoo/api.py", line 463, in __getitem__ return self.registry[model_name]._browse(self, (), ()) File "/usr/lib/python3/dist-packages/odoo/modules/registry.py", line 177, in __getitem__ return self.models[model_name] odoo.tools.convert.ParseError: "hr.leave" while parsing /mnt/extra-addons/augusta_time_off/security/hr_holidays_security.xml:2, near <odoo> <record id="hr_leave_rule_employee" model="ir.rule"> <field name="name">Time Off base.group_user read</field> <field name="model_id" ref="hr_holidays.model_hr_leave"/> <field name="domain_force">[(1,'=',1)]</field> <field name="perm_create" eval="False"/> <field name="perm_write" eval="False"/> <field name="perm_unlink" eval="False"/> <field name="groups" eval="[(4,ref('base.group_user'))]"/> </record> </odoo>

What is wrong? Thanks in advance!


Avatar
Discard
Author Best Answer

in addition what is quite strange:

the record rule I want to change has id=40, and if I use ref = hr_holidays.hr_leave_rule_employee, it creates a new rule referencing the model  ir.qweb.field (XML ID = base.model_ir_qweb_field), and what a coincidence - its id is also 40!

select * from ir_rule where id = 40

...returns 1 record which I want to amend, and I have a feeling that the XML parser somehow looks up for id value (40), not model_id value (197) in ir_model:

select * from ir_model where id = 40
Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
156
0
Aug 21
1198
1
Sep 20
4425
1
Jun 19
3124
2
Nov 24
72