I want to add a javascript code only when the user create a record or update a record for the res.partner
model.
I already tryied to include a javascript file using this technique (and I will explain what it does below) :
<odoo>
<data>
<template id="my_module_script" name="my module script" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/my_module/static/src/js/script.js"></script>
</xpath>
</template>
</data>
</odoo>
This works great, my javascript file is now included... but in any views (and not only for my specific partner create/update view).
QUESTION
Is there any way I can tell odoo to load a specific javascript (or css file as well) for a specific view type (I would like for this example the javascript file loaded for base.view_partner_form
view) ?
If you include your javascript file, it will be compiled to web.assets_backend.js
every time the module is installed.
And web.assets_backend.js
is loaded on every time the backend page is loaded, not when a view is loaded.
Odoo is designed to be a SPA. The javascript files are loaded on the first page load.
So I don't think this should be done by this way (add custom js to a view), but by the Odoo's way: Trigger your code by specific actions.