6

In Odoo/openerp docs and it says 'client actions' are entirely implemented client side that's it. they do not provide any example detailed documentation about it for Odoo v10.

Does anybody have precise idea of how to implement client action and full potential of it. (possibilities that we can implement with client actions.)

DexJ
  • 1,264
  • 13
  • 24

1 Answers1

5

Client actions are basically menu-items defined in xml and the corresponding actions are mapped to a widget.

Following is the implementation of client actions:

Your XML file will contain the following code:

<record id="some-report-client-action" model="ir.actions.client">
  <field name="name">Report Page</field>
  <field name="tag">report.report_page</field>
</record>

<menuitem id="some-report-menuitem" name="Some" parent="pdf_report"
              action="some-report-client-action"/>

Create a js file for creating a widget. It will contain the following code:

openerp.guard_payments = function(instance, local) {
var _t = instance.web._t,
    _lt = instance.web._lt;
var QWeb = instance.web.qweb;

local.HomePage = instance.Widget.extend({
    template: 'MyQWebTemplate',
    init: function(parent, options){
      this._super.apply(this, arguments);
      this.name=parent.name;
    },
    start: function() {
      this._super.apply(this, arguments);
      console.log('Widget Start')
    },
});

//Following code will attach the above widget to the defined client action

instance.web.client_actions.add('report.report_page', 'instance.guard_payments.HomePage');
}

So as you can see we can create a fully custom QWeb template and add any functionality to it.

Basically this the best part provided by Odoo

Sudhanshu Gupta
  • 331
  • 1
  • 6
  • thanks for your answer. i'm working in v10 implemented client action for but facing another problem > template that my widget rendering i am not able to get any values that i pass to it (like. params or any variable I put in widget's init method ) do you have any idea about this?! – DexJ Aug 11 '17 at 06:49
  • Any variable that you declare inside the init method will be available to other methods using the `this` keyword. If you want the variable to be available in the view, you'll have to pass it explicitly to the view like `Qweb.render('MyTemplate', {'variable1': this.variable1})` – Sudhanshu Gupta Aug 13 '17 at 02:07