Created
August 4, 2017 13:21
-
-
Save loristissino/acf3899bc1e0bfc3bb2d56849c834e01 to your computer and use it in GitHub Desktop.
Example of calls in odoo (Javascript and Python model)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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