odoo 中的模板继承 13/14

问题描述

我一直在努力解决这个问题。我有一个模板,里面有一堆 css 和 js 文件。我想扩展模板并再添加一个文件

模板 1

<template id="template1_assets_frontend" name="SP Registration Full Form Assets Frontend" >     
    <script type="text/javascript" src="/test/static/src/js/test1.js" />
</template>

现在我想创建模板2,它扩展模板1并添加一个更多的js文件。 我已经这样使用 inherit_id

<template id="template2_assets_frontend" name="SP Registration Full Form Assets Frontend" inherit_id="template1">
    <xpath expr="//script[last()]" position="after">
        <script type="text/javascript" src="/test/static/src/js/test2.js" />
    </xpath>
</template> 

但问题是,它也在修改 template1。我不想那样。

解决方法

在这上面花了 1-2 个小时之后,我才知道有一个属性 primary="True" 可以实现这一点,它隐藏在此处:https://www.odoo.com/documentation/14.0/reference/data.html#template

所以扩展模板会是这样的:

<template id="template2_assets_frontend" name="SP Registration Full Form Assets Frontend" inherit_id="template1" primary="True">
    <xpath expr="//script[last()]" position="after">
        <script type="text/javascript" src="/test/static/src/js/test2.js" />
    </xpath>
</template> ```