|
@@ -0,0 +1,106 @@
|
|
|
+openerp.variants_by_company_report = function (instance, local) {
|
|
|
+
|
|
|
+ local.ReportWidget = instance.Widget.extend({
|
|
|
+ template: 'ReportContainerTemplate',
|
|
|
+ start: function () {
|
|
|
+ this.fetchLocations();
|
|
|
+ this.fetchCategories();
|
|
|
+
|
|
|
+ this.$el.find('#report_form').submit(_.bind(this.submitForm, this));
|
|
|
+ },
|
|
|
+ fetchLocations: function () {
|
|
|
+ var self = this;
|
|
|
+
|
|
|
+ var StockLocation = new instance.web.Model('stock.location');
|
|
|
+ StockLocation.query(['id', 'name', 'display_name']).filter([['usage', '=', 'internal']]).all().then(function (results) {
|
|
|
+ _.each(results, 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;
|
|
|
+
|
|
|
+ var ProductCategory = new instance.web.Model('product.category');
|
|
|
+ ProductCategory.query().filter([['child_id.child_id.type', '=', 'normal'], ['parent_left', '!=', 0]]).all().then(function (results) {
|
|
|
+ _.each(results, function (item) {
|
|
|
+ self.$el.find('#current-category').append('<option value="' + item.id + '">' + item.display_name + '</option>');
|
|
|
+ });
|
|
|
+ self.$el.find('#current-category').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', 'inventory_value']).filter([['location_id.id', '=', locationId]]).all().then(function (results) {
|
|
|
+ done(results);
|
|
|
+ });
|
|
|
+ },
|
|
|
+ submitForm: function (e) {
|
|
|
+ e.preventDefault();
|
|
|
+ var formData = this.$(e.currentTarget).serializeJSON();
|
|
|
+
|
|
|
+ if (formData.location == 0 | formData.category == 0) {
|
|
|
+ $("#dialog" ).dialog({
|
|
|
+ autoOpen: true,
|
|
|
+ resizable: false,
|
|
|
+ modal: true,
|
|
|
+ title: 'Atención',
|
|
|
+ open: function() {
|
|
|
+ $(this).html('Complete el formulario para generar el reporte');
|
|
|
+ },
|
|
|
+ show: {
|
|
|
+ effect: "shake",
|
|
|
+ duration: 300
|
|
|
+ },
|
|
|
+ hide: {
|
|
|
+ effect: "fade",
|
|
|
+ duration: 300
|
|
|
+ },
|
|
|
+ buttons: {
|
|
|
+ Aceptar: function() {
|
|
|
+ $(this).dialog('close');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var self = this;
|
|
|
+ this.fetchQuantByLocation(formData.location, function (results) {
|
|
|
+ console.log(results);
|
|
|
+ });
|
|
|
+
|
|
|
+ return false;
|
|
|
+ },
|
|
|
+ drawPDF: function (data) {
|
|
|
+ // var columns = ['Product', 'Cantidad'];
|
|
|
+ // var pdfDoc = new window.jsPDF();
|
|
|
+ //
|
|
|
+ // pdfDoc.autoTable(columns, _.map(data, function (item) {
|
|
|
+ // return _.values(_.pick(item, 'product_id', 'qty'));
|
|
|
+ // }), {
|
|
|
+ // theme: 'grid', // 'striped', 'grid' or 'plain',
|
|
|
+ // styles: {
|
|
|
+ // fontSize: 8,
|
|
|
+ // overflow: 'linebreak' // visible, hidden, ellipsize or linebreak
|
|
|
+ // },
|
|
|
+ // showHeader: 'firstPage', // 'everyPage', 'firstPage', 'never',
|
|
|
+ // headerStyles: {
|
|
|
+ // fontStyle: 'bold',
|
|
|
+ // fillColor: '#000'
|
|
|
+ // },
|
|
|
+ // margin: {
|
|
|
+ // top: 30
|
|
|
+ // },
|
|
|
+ // addPageContent: function (data) {
|
|
|
+ // pdfDoc.text('Reporte de Productos', 15, 20);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ //
|
|
|
+ // pdfDoc.output('dataurlnewwindow');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ instance.web.client_actions.add('variants_by_company_report.action_report', 'instance.variants_by_company_report.ReportWidget');
|
|
|
+}
|