|
@@ -27,10 +27,22 @@ openerp.variants_by_company_report = function (instance, local) {
|
|
|
// }
|
|
|
// ],
|
|
|
start: function () {
|
|
|
- this.fetchLocations();
|
|
|
- this.fetchCategories();
|
|
|
+ // this.fetchLocations();
|
|
|
+ // this.fetchCategories();
|
|
|
+ //
|
|
|
+ // this.$el.find('#report_form').submit(_.bind(this.submitForm, this));
|
|
|
|
|
|
- this.$el.find('#report_form').submit(_.bind(this.submitForm, this));
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ $.when(this.fetchLocationsV2(), this.fetchCategoriesV2()).done(function (locations, categories) {
|
|
|
+ console.log(locations);
|
|
|
+ console.log(categories);
|
|
|
+
|
|
|
+ self.fillLocationsOptions(locations);
|
|
|
+ self.fillCategoriesOptions(categories);
|
|
|
+ }).fail(function (errors) {
|
|
|
+ console.log(errors);
|
|
|
+ });
|
|
|
},
|
|
|
// fetch: function (modelName) {
|
|
|
// var modelData = _.find(this.models, function (item) {
|
|
@@ -61,6 +73,25 @@ openerp.variants_by_company_report = function (instance, local) {
|
|
|
self.$el.find('#current-location').append('<option value="9999999">Todas las ubicaciones</option>');
|
|
|
});
|
|
|
},
|
|
|
+ fetchLocationsV2: function () {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var StockLocation = new instance.web.Model('stock.location');
|
|
|
+
|
|
|
+ StockLocation.query(['display_name']).filter([['usage', '=', 'internal']]).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer.promise();
|
|
|
+ },
|
|
|
+ fillLocationsOptions(locations) {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ _.each(locations, function (item) {
|
|
|
+ self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.display_name + '</option>');
|
|
|
+ });
|
|
|
+
|
|
|
+ self.$el.find('#current-location').append('<option value="9999999">Todas las ubicaciones</option>');
|
|
|
+ },
|
|
|
fetchCategories: function () {
|
|
|
var self = this;
|
|
|
|
|
@@ -74,12 +105,40 @@ openerp.variants_by_company_report = function (instance, local) {
|
|
|
self.$el.find('#current-category').append('<option value="9999999">Todas las ubicaciones</option>');
|
|
|
});
|
|
|
},
|
|
|
+ fetchCategoriesV2: function () {
|
|
|
+ var defer = $.Deferred();
|
|
|
+ var ProductCategory = new instance.web.Model('product.category');
|
|
|
+
|
|
|
+ ProductCategory.query(['display_name', 'child_id']).filter([['child_id.child_id.type', '=', 'normal'], ['parent_left', '!=', 0]]).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer.promise();
|
|
|
+ },
|
|
|
+ fillCategoriesOptions(categories) {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ _.each(categories, function (item) {
|
|
|
+ self.$el.find('#current-location').append('<option value="' + item.id + '">' + item.display_name + '</option>');
|
|
|
+ });
|
|
|
+
|
|
|
+ self.$el.find('#current-location').append('<option value="9999999">Todas las ubicaciones</option>');
|
|
|
+ },
|
|
|
fetchQuantByLocation: function (locationId, done) {
|
|
|
var StockQuant = new instance.web.Model('stock.quant');
|
|
|
StockQuant.query(['product_id', 'qty']).filter([['location_id.id', '=', locationId], ['qty', '>', 0]]).all().then(function (results) {
|
|
|
done(results);
|
|
|
});
|
|
|
},
|
|
|
+ fetchQuantByLocationV2: function (locationId) {
|
|
|
+ var defer = $.Deferred();
|
|
|
+
|
|
|
+ StockQuant.query(['product_id', 'qty']).filter([['location_id.id', '=', locationId], ['qty', '>', 0]]).all().then(function (results) {
|
|
|
+ defer.resolve(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return defer.promise();
|
|
|
+ },
|
|
|
submitForm: function (e) {
|
|
|
e.preventDefault();
|
|
|
var formData = this.$(e.currentTarget).serializeJSON();
|