Sujan
Sujan

Reputation: 21

call_button() missing 1 required positional argument: 'method' odoo

I am trying to call js function on button click but i am getting call_button() missing 1 required positional argument: 'method' error.

For location_tracker.js which includes my on click button function

odoo.define('location_tracker.location_tracker', function (require) {
"use strict";

var FormController = require('web.FormController');

FormController.include({
    _onButtonClicked: function (event) {
           if(event.data.attrs.id === "set_location"){
             alert("OK");
           }
           this._super(event);
        }
    });
});

For view.xml which has name field and set location button

<record id="location_tracker_form_view" model="ir.ui.view">
        <field name="name">location.tracker.form.view</field>
        <field name="model">location_tracker</field>
        <field name="arch" type="xml">
            <form>
               <header>
                   <button id="set_location" type="object" 
                     string="SetLocation"/>
               </header>
                <sheet>
                     <group>
                        <field name="name"/>
                        <field name="latitude"/>
                        <field name="longitude"/>
                     </group>
                </sheet>
            </form>
        </field>
</record>

<template id="assets_backend" name="location_tracker assets" 
       inherit_id="web.assets_backend">
    <xpath expr="." position="inside">
        <script type="text/javascript" 
         src="/location_tracker/static/src/js/location_tracker.js"> 
       </script>
    </xpath>
</template>

For model.py for my model

from odoo import models, fields, api
class LocationTracker(models.Model):

  _name = 'location_tracker'
  name = fields.Char(string="Notes")
  location_tracker_id = fields.Char(string="Id")
  latitude = fields.Float(string="Latitude", digits=(16,7), 
   readonly=True)
  longitude = fields.Float(string="Longitude", digits=(16,7), 
 readonly=True)

def set_location(self):
   print ('Called')

Upvotes: 2

Views: 904

Answers (1)

Karara Mohamed
Karara Mohamed

Reputation: 933

You need to add a name attr in button and set the method name exist in a python file.

<button 
    id="set_location" 
    type="object"
    name="set_location"
    string="SetLocation"/>

Upvotes: 1

Related Questions