gpt4 book ai didi

odoo - 如何删除 "sheet"节点以保持其内容不变?

转载 作者:行者123 更新时间:2023-12-05 01:02:30 25 4
gpt4 key购买 nike

我想删除节点 <sheet></sheet>从表单 View 。例如,我有这样的观点:

<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>
<sheet>
<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>
</sheet>
</form>
</field>
</record>

我想在没有节点的情况下在另一个 View 中转换它,但保留其中的所有元素:

<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>

<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>

</form>
</field>
</record>

这可能吗,还是我需要再次覆盖完整的代码?

可能类似于:

<xpath expr="//form/sheet" position="replace">
<!-- [...] -->
</xpath>

Git Hub 中有一个 Unresolved 问题要求解决这个 here ,但我认为也许任何人都知道如何在不在 Odoo 中编写新功能的情况下做到这一点。

最佳答案

只需使用 fields_view_get:

    from lxml import etree
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
doc = etree.XML(res['arch'])
for sheet in doc.xpath("//sheet"):
parent = sheet.getparent()
index = parent.index(sheet)
for child in sheet:
parent.insert(index, child)
index += 1
parent.remove(sheet)
res['arch'] = etree.tostring(doc)
return res

改进了 oe_chatting 存在的情况

关于odoo - 如何删除 "sheet"节点以保持其内容不变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32694804/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com