Skip to content

Instantly share code, notes, and snippets.

@loristissino
Created August 4, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loristissino/acf3899bc1e0bfc3bb2d56849c834e01 to your computer and use it in GitHub Desktop.
Save loristissino/acf3899bc1e0bfc3bb2d56849c834e01 to your computer and use it in GitHub Desktop.
Example of calls in odoo (Javascript and Python model)
JavaScript:
odoo.define('stock.my_javascript', function (require) {
"use strict";
var Model = require('web.Model');
var stock_location = new Model('stock.location');
var c = stock_location.call('my_function', [95]);
$.when(c).done(function(data) {
console.log(data);
var boxes = JSON.parse(data);
for (var i=0; i<boxes.length; i++)
{
/*
*/
}
});
});
model (python)
@api.model
def my_function(self, location_id):
locations = self.search( [('location_id', '=', location_id)] )
myvalues = []
for location in locations:
myvalues.append( {
'corridor': location['posx'],
'shelf': location['posy'],
'height': location['posz'],
'slot_depth': location['sizex'],
'slot_width': location['sizey'],
'slot_height': location['sizez'],
'opacity': 500,
'id' : location['id'],
'color': 'green',
'type': 'big',
}
)
return json.dumps( myvalues )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment