Git Product home page Git Product logo

odoo_js_tutorial's Introduction

odoo web rpc tutorial

1. How to read template input values examples

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

var Widget= require('web.Widget');
var widgetRegistry = require('web.widget_registry');

var changeTitle = function() {
        opp_name.value = value_input.value;
    };
    
var MyWidget = Widget.extend({

    template: 'sigPad',

    events: {
        'click .your_class': 'change_opp_name',
    },

    change_opp_name: function () {
        var opp_name = document.getElementById("o_field_input_21");
        var value_input = document.getElementById('value_input');
        var change_opp_name_button = document.getElementById('change_opp_name_button');
        var event = new Event('change');
        change_opp_name_button.addEventListener('change', changeTitle(), false);
        opp_name.dispatchEvent(event);
    }
});

widgetRegistry.add(
    'my_widget', MyWidget
);

return MyWidget;
<?xml version="1.0" encoding="utf-8"?>
<templates>
    <t t-name="sigPad">
        <div>
            <input type="text" id="value_input" class="form-control" style="max-width: 400px;  width: 150px"/>
            <input type="button" id="change_opp_name_button" class="your_class" value="Submit"/>
        </div>
    </t>
</templates>

2. FormController

var FormController = require('web.FormController');
var ExtendFormController = FormController.include({
    saveRecord: function () {
        var res = this._super.apply(this, arguments);
        if(this.modelName == 'project.task'){
            var self = this;
            res.then(function(changedFields){
                console.log(changedFields);
                console.log(self.modelName);
                self.do_notify('title', 'message');
                // you can call a method on the server like this
                self._rpc({
                        model: self.modelName,
                        method: 'search_read',
                        fields: ['name'],
                        context: self.context,
                    }).then(function(result){
                        console.log('rpc result');
                        console.log(result);
                    })
            });
        }
        return res;
    }
});
odoo.define('odoo_js_tutorial.odoo_tutorial', function (require) {
    'use strict';
    console.log('popup.js loaded');
    var FormController = require('web.FormController');

    var ExtendFormController = FormController.include({
        saveRecord: function (recordID) {
            
            var res = this._super.apply(this, arguments);
            console.log(res);
            if (this.modelName == 'odoo.tutorial'){
                console.log('saveRecord');
                console.log(recordID);
                this.do_notify('Success', 'Record Saved');
            }
            return res;
        }
    });

});

You also need to inherit the createRecord() method the same way.

A few notes:

the first console log line saying: ["name"] is the value of changedFields (I only changed the name of the task before hitting Save) I was working on the project.task object but you can change that to sale.order :) The official documentation is very helpful

odoo_js_tutorial's People

Contributors

bithabib avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.