字段domain过滤权限问题,请各位大大看看
-
@digitalsatori 谢谢回复,按您所说试了下报如下错误:
Odoo Server Error
Traceback (most recent call last):
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 1108, in _validate_fields
check(self)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 351, in _check_xml
self.postprocess_and_fields(view.model, view_doc, view.id)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 1119, in postprocess_and_fields
self.raise_view_error("\n".join(msg_lines), view_id)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 548, in raise_view_error
raise ValueError(message)
ValueError: 用在属性的字段 'ref' 必须出现在视图,但是此处有遗漏:- 'ref' in domain="[('group_id.id', '=', ref('yz_group_user'))]"
错误的上下文:
视图审批单
[view_id: 1507, xml_id: business_entertainment.view_form_business, model: business.entertainment.sheet, parent_id: n/a]During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 758, in parse
self._tags[rec.tag](rec, de, mode=mode)
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 663, in _tag_record
record = model.with_context(rec_context)._load_records([data], self.mode == 'update')
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3838, in _load_records
data['record']._load_records_write(data['values'])
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3776, in _load_records_write
self.write(values)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write
return super(View, self).write(self._compute_defaults(vals))
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3347, in write
fields[0].determine_inverse(records)
File "E:\workdata\PycharmProjects\odoo-12\odoo\fields.py", line 1117, in determine_inverse
getattr(records, self.inverse)()
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 275, in _inverse_arch
view.write(data)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write
return super(View, self).write(self._compute_defaults(vals))
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3321, in write
self._write(store_vals)
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3457, in _write
self._validate_fields(vals)
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 1112, in validate_fields
raise ValidationError("%s\n\n%s" % (("Error while validating constraint"), tools.ustr(e)))
odoo.exceptions.ValidationError: ('constraint 检查错误\n\n用在属性的字段 'ref' 必须出现在视图,但是此处有遗漏:\n- 'ref' in domain="[('group_id.id', '=', ref('yz_group_user'))]"\n\n错误的上下文:\n视图审批单
\n[view_id: 1507, xml_id: business_entertainment.view_form_business, model: business.entertainment.sheet, parent_id: n/a]', None)During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 656, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 314, in _handle_exception
raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\pycompat.py", line 87, in reraise
raise value
File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 698, in dispatch
result = self._call_function(**self.params)
File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 346, in _call_function
return checked_call(self.db, *args, **kwargs)
File "E:\workdata\PycharmProjects\odoo-12\odoo\service\model.py", line 97, in wrapper
return f(dbname, *args, **kwargs)
File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 339, in checked_call
result = self.endpoint(*a, **kw)
File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 941, in call
return self.method(*args, **kw)
File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 519, in response_wrap
response = f(*args, **kw)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\web\controllers\main.py", line 966, in call_button
action = self._call_kw(model, method, args, {})
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\web\controllers\main.py", line 954, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "E:\workdata\PycharmProjects\odoo-12\odoo\api.py", line 749, in call_kw
return _call_kw_multi(method, model, args, kwargs)
File "E:\workdata\PycharmProjects\odoo-12\odoo\api.py", line 736, in _call_kw_multi
result = method(recs, *args, **kwargs)
File "", line 2, in button_immediate_upgrade
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_module.py", line 74, in check_and_log
return method(self, *args, **kwargs)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_module.py", line 622, in button_immediate_upgrade
return self._button_immediate_function(type(self).button_upgrade)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_module.py", line 561, in _button_immediate_function
modules.registry.Registry.new(self._cr.dbname, update_module=True)
File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\registry.py", line 86, in new
odoo.modules.load_modules(registry._db, force_demo, status, update_module)
File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 417, in load_modules
force, status, report, loaded_modules, update_module, models_to_check)
File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 313, in load_marked_modules
perform_checks=perform_checks, models_to_check=models_to_check
File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 222, in load_module_graph
load_data(cr, idref, mode, kind='data', package=package, report=report)
File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 68, in load_data
tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report)
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 802, in convert_file
convert_xml_import(cr, module, fp, idref, mode, noupdate, report)
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 865, in convert_xml_import
obj.parse(doc.getroot(), mode=mode)
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 764, in parse
exc_info[2]
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\pycompat.py", line 86, in reraise
raise value.with_traceback(tb)
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 758, in parse
self._tags[rec.tag](rec, de, mode=mode)
File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 663, in _tag_record
record = model.with_context(rec_context)._load_records([data], self.mode == 'update')
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3838, in _load_records
data['record']._load_records_write(data['values'])
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3776, in _load_records_write
self.write(values)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write
return super(View, self).write(self._compute_defaults(vals))
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3347, in write
fields[0].determine_inverse(records)
File "E:\workdata\PycharmProjects\odoo-12\odoo\fields.py", line 1117, in determine_inverse
getattr(records, self.inverse)()
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 275, in _inverse_arch
view.write(data)
File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write
return super(View, self).write(self._compute_defaults(vals))
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3321, in write
self._write(store_vals)
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3457, in _write
self._validate_fields(vals)
File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 1112, in validate_fields
raise ValidationError("%s\n\n%s" % (("Error while validating constraint"), tools.ustr(e)))
odoo.tools.convert.ParseError: "constraint 检查错误用在属性的字段 'ref' 必须出现在视图,但是此处有遗漏:
- 'ref' in domain="[('group_id.id', '=', ref('yz_group_user'))]"
错误的上下文:
视图审批单
[view_id: 1507, xml_id: business_entertainment.view_form_business, model: business.entertainment.sheet, ```
code_textNone" while parsing file:/e:/workdata/pycharmprojects/odoo-12/odoo/myaddons/business_entertainment/views/business_view.xml:24, near <record id="view_form_business" model="ir.ui.view"> <field name="name">审批单</field> <field name="model">business.entertainment.sheet</field> <field name="arch" type="xml">
-
只注意了你domain的写法,你是添加在view里啊。试试下面的方法:
不要添加在view里,添加在python文件的该字段的定义里:
user = fields.Many2one('res.users', domain=lambda self: [('groups_id.id', '=', self.env.ref('权限组xmlid').id)])
-
@digitalsatori 在 字段domain过滤权限问题,请各位大大看看 中说:
domain=lambda self: [('groups_id.id', '=', self.env.ref('权限组xmlid').id)]
因为我之前试了下,在字段里和在view里效果一样,所以就写view里了,方便更新。
您这个我试了下还是报错:Odoo Server Error Traceback (most recent call last): File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\cache.py", line 88, in lookup r = d[key] File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\func.py", line 69, in wrapper return func(self, *args, **kwargs) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\lru.py", line 44, in __getitem__ a = self.d[obj].me KeyError: ('ir.model.data', <function IrModelData.xmlid_lookup at 0x0000000003D5D798>, 'yz_group_bm') During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 1108, in _validate_fields check(self) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 351, in _check_xml self.postprocess_and_fields(view.model, view_doc, view.id) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 1085, in postprocess_and_fields fields = Model.fields_get(None) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 2684, in fields_get description = field.get_description(self.env) File "E:\workdata\PycharmProjects\odoo-12\odoo\fields.py", line 746, in get_description value = value(env) File "E:\workdata\PycharmProjects\odoo-12\odoo\fields.py", line 2049, in _description_domain return self.domain(env[self.model_name]) if callable(self.domain) else self.domain File "e:\workdata\pycharmprojects\odoo-12\odoo\myaddons\business_entertainment\models\business_entertainment_sheet.py", line 28, in <lambda> domain=lambda self: [('groups_id.id', '=', self.env.ref('yz_group_bm').id)]) File "E:\workdata\PycharmProjects\odoo-12\odoo\api.py", line 854, in ref return self['ir.model.data'].xmlid_to_object(xml_id, raise_if_not_found=raise_if_not_found) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_model.py", line 1420, in xmlid_to_object t = self.xmlid_to_res_model_res_id(xmlid, raise_if_not_found) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_model.py", line 1404, in xmlid_to_res_model_res_id return self.xmlid_lookup(xmlid)[1:3] File "<decorator-gen-25>", line 2, in xmlid_lookup File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\cache.py", line 93, in lookup value = d[key] = self.method(*args, **kwargs) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_model.py", line 1390, in xmlid_lookup module, name = xmlid.split('.', 1) ValueError: not enough values to unpack (expected 2, got 1) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 758, in parse self._tags[rec.tag](rec, de, mode=mode) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 663, in _tag_record record = model.with_context(rec_context)._load_records([data], self.mode == 'update') File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3838, in _load_records data['record']._load_records_write(data['values']) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3776, in _load_records_write self.write(values) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write return super(View, self).write(self._compute_defaults(vals)) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3347, in write fields[0].determine_inverse(records) File "E:\workdata\PycharmProjects\odoo-12\odoo\fields.py", line 1117, in determine_inverse getattr(records, self.inverse)() File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 275, in _inverse_arch view.write(data) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write return super(View, self).write(self._compute_defaults(vals)) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3321, in write self._write(store_vals) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3457, in _write self._validate_fields(vals) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 1112, in _validate_fields raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e))) odoo.exceptions.ValidationError: ('constraint 检查错误\n\nnot enough values to unpack (expected 2, got 1)', None) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 656, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 314, in _handle_exception raise pycompat.reraise(type(exception), exception, sys.exc_info()[2]) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\pycompat.py", line 87, in reraise raise value File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 698, in dispatch result = self._call_function(**self.params) File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 346, in _call_function return checked_call(self.db, *args, **kwargs) File "E:\workdata\PycharmProjects\odoo-12\odoo\service\model.py", line 97, in wrapper return f(dbname, *args, **kwargs) File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 339, in checked_call result = self.endpoint(*a, **kw) File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 941, in __call__ return self.method(*args, **kw) File "E:\workdata\PycharmProjects\odoo-12\odoo\http.py", line 519, in response_wrap response = f(*args, **kw) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\web\controllers\main.py", line 966, in call_button action = self._call_kw(model, method, args, {}) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\web\controllers\main.py", line 954, in _call_kw return call_kw(request.env[model], method, args, kwargs) File "E:\workdata\PycharmProjects\odoo-12\odoo\api.py", line 749, in call_kw return _call_kw_multi(method, model, args, kwargs) File "E:\workdata\PycharmProjects\odoo-12\odoo\api.py", line 736, in _call_kw_multi result = method(recs, *args, **kwargs) File "<decorator-gen-67>", line 2, in button_immediate_upgrade File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_module.py", line 74, in check_and_log return method(self, *args, **kwargs) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_module.py", line 622, in button_immediate_upgrade return self._button_immediate_function(type(self).button_upgrade) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_module.py", line 561, in _button_immediate_function modules.registry.Registry.new(self._cr.dbname, update_module=True) File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\registry.py", line 86, in new odoo.modules.load_modules(registry._db, force_demo, status, update_module) File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 417, in load_modules force, status, report, loaded_modules, update_module, models_to_check) File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 313, in load_marked_modules perform_checks=perform_checks, models_to_check=models_to_check File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 222, in load_module_graph load_data(cr, idref, mode, kind='data', package=package, report=report) File "E:\workdata\PycharmProjects\odoo-12\odoo\modules\loading.py", line 68, in load_data tools.convert_file(cr, package.name, filename, idref, mode, noupdate, kind, report) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 802, in convert_file convert_xml_import(cr, module, fp, idref, mode, noupdate, report) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 865, in convert_xml_import obj.parse(doc.getroot(), mode=mode) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 764, in parse exc_info[2] File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\pycompat.py", line 86, in reraise raise value.with_traceback(tb) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 758, in parse self._tags[rec.tag](rec, de, mode=mode) File "E:\workdata\PycharmProjects\odoo-12\odoo\tools\convert.py", line 663, in _tag_record record = model.with_context(rec_context)._load_records([data], self.mode == 'update') File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3838, in _load_records data['record']._load_records_write(data['values']) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3776, in _load_records_write self.write(values) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write return super(View, self).write(self._compute_defaults(vals)) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3347, in write fields[0].determine_inverse(records) File "E:\workdata\PycharmProjects\odoo-12\odoo\fields.py", line 1117, in determine_inverse getattr(records, self.inverse)() File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 275, in _inverse_arch view.write(data) File "e:\workdata\pycharmprojects\odoo-12\odoo\addons\base\models\ir_ui_view.py", line 444, in write return super(View, self).write(self._compute_defaults(vals)) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3321, in write self._write(store_vals) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3457, in _write self._validate_fields(vals) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 1112, in _validate_fields raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e))) odoo.tools.convert.ParseError: "constraint 检查错误 not enough values to unpack (expected 2, got 1) None" while parsing file:/e:/workdata/pycharmprojects/odoo-12/odoo/myaddons/business_entertainment/views/business_view.xml:4, near <record id="view_tree_business" model="ir.ui.view">
是不是不能用等号呀,一个用户可能兼有多个权限组
-
@万叶言雨 在 字段domain过滤权限问题,请各位大大看看 中说:
是不是不能用等号呀,一个用户可能兼有多个权限组
你说的对,domain改成:
user = fields.Many2one('res.users', domain=lambda self: [('groups_id', 'in', self.env.ref('权限组xmlid').ids)])
你上面的错误应该是xmlid错了,xmlid必须是
模块名.xmlid
,即使在本模块中定义的xmlid也要带上本模块的名字。另外,之所以这里要将domain定义在python文件的field上的原因是我们需要将xmlid解析为数据库id,在前端处理很麻烦,需要先eval这个
ref(xxxx)
-
@digitalsatori
groups_id不需要加.id么。这个in是前面元素是否在后面元素列表里,我看后面只是单个权限组,前面groups_id是res_users模型的群组,应该是列表字段吧 -
@万叶言雨 加上模块名报这个,找不到id:
self._write(store_vals) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 3457, in _write self._validate_fields(vals) File "E:\workdata\PycharmProjects\odoo-12\odoo\models.py", line 1112, in _validate_fields raise ValidationError("%s\n\n%s" % (_("Error while validating constraint"), tools.ustr(e))) odoo.tools.convert.ParseError: "constraint 检查错误 External ID not found in the system: business.entertainment.sheet.yz_group_bm None" while parsing file:/e:/workdata/pycharmprojects/odoo-12/odoo/myaddons/business_entertainment/views/business_view.xml:4, near <record id="view_tree_business" model="ir.ui.view">
-
你的报错,是view里的错误啊。
business.entertainment.sheet.yz_group_bm
这是什么? -
@万叶言雨 在 字段domain过滤权限问题,请各位大大看看 中说:
@digitalsatori
groups_id不需要加.id么。这个in是前面元素是否在后面元素列表里,我看后面只是单个权限组,前面groups_id是res_users模型的群组,应该是列表字段吧不需要。的确,真正的语意是倒过来才对,但是左侧必须是对象上的字段,所以Odoo会做这个反转的逻辑操作的。
-
@digitalsatori
business.entertainment.sheet是模型_name,view里domain去掉了 -
嗯,不过从你view里报的错就知道你的xmlid写得还是不对,
模块名.xmlidxxxxxxxx
不是 “模型名.xmlidxxxxxxx" -
@digitalsatori 嗯嗯,可以了。刚看错了:disappointed_but_relieved_face: ,非常感谢
-
不客气,很高兴对你有帮助。