Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to get the current Cordinate in OpenERP/Odoo ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 600
    Comment on it

    For current cordinate we have to add a button resetting the product's coordinates to the location of the user, you can get these coordinates using the javascript geolocation API.
    Now we would like to display an additional button to automatically set the coordinates to the location of the current user.For example code is like below.

    local.WidgetCoordinates = instance.web.form.FormWidget.extend({
        events: {
            'click button': function () {
                navigator.geolocation.getCurrentPosition(
                    this.proxy('received_position'));
            }
        },
        start: function() {
            var sup = this._super();
            this.field_manager.on("field_changed:provider_latitude", this, this.display_map);
            this.field_manager.on("field_changed:provider_longitude", this, this.display_map);
            this.on("change:effective_readonly", this, this.display_map);
            this.display_map();
            return sup;
        },
        display_map: function() {
            this.$el.html(QWeb.render("WidgetCoordinates", {
                "latitude": this.field_manager.get_field_value("provider_latitude") || 0,
                "longitude": this.field_manager.get_field_value("provider_longitude") || 0,
            }));
            this.$("button").toggle(! this.get("effective_readonly"));
        },
        received_position: function(obj) {
            this.field_manager.set_values({
                "provider_latitude": obj.coords.latitude,
                "provider_longitude": obj.coords.longitude,
            });
        },
    });
    

    Note- user should not be able to click on that button when the form view is in read-only mode.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: