Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
12772 Widoki

I have been trying (for days) to pass the context from my XML view to my own JavaScript function as I need the active_id.

The JavaScript function gets data from an external source and populates the table with it, but I need to get the current active_id... Please help!!! This has been driving me insane, all I need is the active_id and nothing else. If there is a way to get this from a pre-existent variable within JavaScript, please let me know what it is.

If I need to use Python, I can, but I do not know how to actually populate my table (it can't be a field) from Python as the documentation does not actually say where returned values go...

Here's an example of my code:

<record id="my_module.example_form" model="ir.ui.view">
        <field name="name">my_module.example_form</field>
        <field name="model">res.partner</field>
        <field name="type">form</field>
        <field name="arch" type="xml">
            <form string="Example Form" version="7.0">
             <script type="text/javascript">
                 $('#My_Table').ready(function() {
                     buildAccountsTable(context);
                 });
             </script>
                <table id="My_Table">
                 ...
                </table>
           </form>
         </field>
</record>
Awatar
Odrzuć

Hi did you succeed? I need help along the same lines

Najlepsza odpowiedź

I encountered a similar situation while using Odoo 13. Specifically, I needed to hide the 'Create' button but retain the 'Import' button. Unfortunately, Odoo 13 does not directly support this functionality, as the 'Import' button is displayed only when the 'Create' button is visible. To work around this limitation, I implemented a solution by passing context from the view to my JS script, allowing me to dynamically determine whether the 'Create' button should be hidden.

XML:
`

            Page Name

            model.name

            tree

           

           

            current

            {                
"hide_add_button": 1

            }

           

        `

js
`odoo.define("module_name.button", function (require) {

  "use strict";


  var core = require("web.core");

  var ListController = require("web.ListController");


  var _t = core._t;


  ListController.include({

    renderButtons: function () {

      let context = this.model.get(this.handle, { raw: true }).getContext();


      this._super.apply(this, arguments);


      if (this.$buttons) {

        var addButton = this.$buttons.find(

          ".btn.btn-primary.o_list_button_add"

        );


        // add context hide_add_button : 1 in XML to hide the add button

        if (context.hide_add_button) {

          addButton.css("display", "none");

        }

      }

    },

  });

});

`


Awatar
Odrzuć
Najlepsza odpowiedź

Hi may you know, how get context?

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
sie 20
9040
2
cze 20
4098
2
mar 19
13080
2
lip 24
1292
2
cze 23
42498