如何在 Python 侧创建扩展表单视图?
How to Create Extension Form View in Python Side?
我正在尝试创建动态视图,所以我想在 python 端创建视图。但是当我尝试保存视图时,"arch_base" 字段未设置。有人可以告诉我有什么问题吗?这是我的功能
@api.onchange('field_id')
def create_validation_button(self):
model = self.field_id.model_id.model
model_view = self.env['ir.ui.view'].search([("model", "=", model), ('type', "=", "form")])
arch = '<xpath expr="//header" postition="inside"><button string="Add Followers" type="object" name="add_project_followers" /></xpath>'
if model_view:
self.view_id = None
self.env['ir.ui.view'].search(
[("model", "=", model), ('name', "=", 'validation.' + model_view.name)]).unlink()
view_data = {'name': 'validation.' + model_view.name, 'type': 'form', 'model': model, 'priority': 1,
'inherit_id': model_view.id,
'mode': 'extension',
'arch_base': arch.encode('utf-8')}
view = self.env["ir.ui.view"].create(view_data)
self.view_id = view
字段名称是 arch
而不是 arch_base
所以集合将是 :
view_data = {'name': 'validation.' + model_view.name, 'type': 'form', 'model': model, 'priority': 1,
'inherit_id': model_view.id,
'mode': 'extension',
'arch': arch.encode('utf-8')}
感谢
Peter Alabaster
https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-create-extension-form-view-in-python-side-119479
我正在尝试创建动态视图,所以我想在 python 端创建视图。但是当我尝试保存视图时,"arch_base" 字段未设置。有人可以告诉我有什么问题吗?这是我的功能
@api.onchange('field_id')
def create_validation_button(self):
model = self.field_id.model_id.model
model_view = self.env['ir.ui.view'].search([("model", "=", model), ('type', "=", "form")])
arch = '<xpath expr="//header" postition="inside"><button string="Add Followers" type="object" name="add_project_followers" /></xpath>'
if model_view:
self.view_id = None
self.env['ir.ui.view'].search(
[("model", "=", model), ('name', "=", 'validation.' + model_view.name)]).unlink()
view_data = {'name': 'validation.' + model_view.name, 'type': 'form', 'model': model, 'priority': 1,
'inherit_id': model_view.id,
'mode': 'extension',
'arch_base': arch.encode('utf-8')}
view = self.env["ir.ui.view"].create(view_data)
self.view_id = view
字段名称是 arch
而不是 arch_base
所以集合将是 :
view_data = {'name': 'validation.' + model_view.name, 'type': 'form', 'model': model, 'priority': 1,
'inherit_id': model_view.id,
'mode': 'extension',
'arch': arch.encode('utf-8')}
感谢
Peter Alabaster https://www.odoo.com/fr_FR/forum/aide-1/question/how-to-create-extension-form-view-in-python-side-119479