修改Odoo中现有的xpath表达式

修改Odoo中现有的xpath表达式,xpath,replace,odoo,Xpath,Replace,Odoo,我必须在自定义模块中修改Odoo模块的xpath。考虑下面的V11的WebStestySuffice模块的代码(为了简单起见,我已经减少代码): 替代产品: 例如,我想替换 1) position=“after”到position=“before” 或 2) expr=“//div[@id='product\u full\u description']”到expr=“//div[@id='product\u small\u description']” 我该怎么做呢?像这样试试 <te

我必须在自定义模块中修改Odoo模块的xpath。考虑下面的V11的WebStestySuffice模块的代码(为了简单起见,我已经减少代码):


替代产品:
例如,我想替换

1) position=“after”到position=“before”

2) expr=“//div[@id='product\u full\u description']”到expr=“//div[@id='product\u small\u description']”

我该怎么做呢?

像这样试试

<template id="recommended_products" inherit_id="website_sale.product" customize_show="True" name="Alternative Products">
    <!-- this will replace the existing place of the div -->
    <xpath expr="//div[@id='product_full_description']" position="replace">
    </xpath>
    <!-- this will be the new place of the div. Instead of after you use before -->
     <xpath expr="//div[@id='product_full_description']" position="before">
        <div class="container mt32" t-if="product.alternative_product_ids">
            <h3>Alternative Products:</h3>                                        
        </div>
    </xpath>
</template>

替代产品:
像这样试试

<template id="recommended_products" inherit_id="website_sale.product" customize_show="True" name="Alternative Products">
    <!-- this will replace the existing place of the div -->
    <xpath expr="//div[@id='product_full_description']" position="replace">
    </xpath>
    <!-- this will be the new place of the div. Instead of after you use before -->
     <xpath expr="//div[@id='product_full_description']" position="before">
        <div class="container mt32" t-if="product.alternative_product_ids">
            <h3>Alternative Products:</h3>                                        
        </div>
    </xpath>
</template>

替代产品:

在这里,我将解释一种非常罕见(无文档记录)且有用的Odoo XML视图继承,它能够替换整个视图而不重写记录视图数据

例如,如果您想覆盖(坏习惯)视图
网站\u sale.product
的内容,您可以这样做(使用另一条记录的相同记录xml id)


...
...
这会带来丢失原始代码的不便,并且在卸载引入更改的模块时可能会失败,因为更改将保留在原始记录视图中,并导致一些错误

建议的方法(罕见且未记录)是使用这种继承:

<template id="recommended_products_ext" inherit_id="website_sale.recommended_products">
    <xpath expr="." position="replace">
        <t name="Alternative Products" t-name="website_sale.recommended_products">
            ...
            <!-- Reorganize the original view as needed -->
            ...
        </t>
    </xpath>
</template>

...
...
此格式允许通过扩展引入原始视图替代,而无需手动修改继承视图的原始代码。实际上,格式:
是Odoo在DB中存储qweb模板的方式,我从中受益,它允许我引入整个视图覆盖,同时很好地处理同一视图的其他继承

请记住,这是一个可能需要模块依赖项和视图优先级帮助的工具,以便在其他视图继承可以使用它们之前,尽快执行注入更改的操作

我觉得这个问题是分享这个解决方案的好地方。但是如果你申请你的案子,请随意评估

*更新* 示例要点:


在这里,我将解释一种非常罕见(无文档记录)且有用的Odoo XML视图继承,它能够替换整个视图而不重写记录视图数据

例如,如果您想覆盖(坏习惯)视图
网站\u sale.product
的内容,您可以这样做(使用另一条记录的相同记录xml id)


...
...
这会带来丢失原始代码的不便,并且在卸载引入更改的模块时可能会失败,因为更改将保留在原始记录视图中,并导致一些错误

建议的方法(罕见且未记录)是使用这种继承:

<template id="recommended_products_ext" inherit_id="website_sale.recommended_products">
    <xpath expr="." position="replace">
        <t name="Alternative Products" t-name="website_sale.recommended_products">
            ...
            <!-- Reorganize the original view as needed -->
            ...
        </t>
    </xpath>
</template>

...
...
此格式允许通过扩展引入原始视图替代,而无需手动修改继承视图的原始代码。实际上,格式:
是Odoo在DB中存储qweb模板的方式,我从中受益,它允许我引入整个视图覆盖,同时很好地处理同一视图的其他继承

请记住,这是一个可能需要模块依赖项和视图优先级帮助的工具,以便在其他视图继承可以使用它们之前,尽快执行注入更改的操作

我觉得这个问题是分享这个解决方案的好地方。但是如果你申请你的案子,请随意评估

*更新* 示例要点:


谢谢你,阿克塞尔。但我不明白我该怎么做。考虑到上述代码和我的要求,你能举一个例子来说明吗?想法是将原始视图代码复制到
标记中,并重新组织它,而无需将相同的代码从一个位置替换和插入到另一个位置,只需根据需要进行修改。我不想在答案中用一个具体的例子来改变代码。但是为了向您展示如何在您的场景中实现这一点,让我给您一个要点:谢谢Alex。很抱歉反应太晚。我将尝试让您知道。当我尝试将位置“after”替换为“before”时,出现以下错误:如果我直接在原始代码中更新,则无法在父视图中找到元素“”,那么它可以正常工作。你能帮帮我出什么事了吗?有时候我觉得odoo没有合适的模板继承方法。对不起,Ankit,我已经测试过了,你是对的。我的稀有视图继承似乎只适用于基本视图(非继承视图)。我必须继续研究这个话题以找到完整的解决方案,因为它带来了新的做事方式Hanks,Axel。但我不明白我该怎么做。考虑到上述代码和我的要求,你能举一个例子来说明吗?想法是将原始视图代码复制到
标记中,并重新组织它,而无需将相同的代码从一个位置替换和插入到另一个位置,只需根据需要进行修改。我不想在答案中用一个具体的例子来改变代码。但是为了向您展示如何在您的场景中实现这一点,让我给您一个要点:谢谢Alex。很抱歉反应太晚。我将尝试让您知道。当我尝试将位置“after”替换为“before”时,出现以下错误:如果我直接在原始代码中更新,则无法在父视图中找到元素“”,那么它可以正常工作。你能帮帮我出什么事了吗?有时候我觉得odoo没有合适的模板继承方法。对不起,Ankit,我已经测试过了,你是对的。看见