From 476ebd08d768be144ee2c65aca579c94085a5cd6 Mon Sep 17 00:00:00 2001 From: Haresh Shyara Date: Wed, 17 Jan 2018 14:36:32 +0530 Subject: [PATCH] [IMP]stock: lot_serial number clickable on traceability report - click on lot/serial number directly send to the traceability of that SN --- addons/stock/models/stock_traceability.py | 17 ++++++++++------- .../src/js/stock_traceability_report_backend.js | 4 ++-- .../src/js/stock_traceability_report_widgets.js | 14 ++++++-------- .../src/xml/stock_traceability_report_line.xml | 11 ++++++++--- .../stock/views/report_stock_traceability.xml | 6 +++--- 5 files changed, 29 insertions(+), 23 deletions(-) diff --git a/addons/stock/models/stock_traceability.py b/addons/stock/models/stock_traceability.py index 89ffdfbc8ec..f43a0977827 100644 --- a/addons/stock/models/stock_traceability.py +++ b/addons/stock/models/stock_traceability.py @@ -51,7 +51,7 @@ class MrpStockReport(models.TransientModel): move_line = self.env['stock.move.line'] if rec_id and model in ('stock.production.lot', 'stock.move.line'): lines = self.env['stock.move.line'].search([ - ('lot_id', '=', context.get('lot_id') or rec_id), + ('lot_id', '=', context.get('lot_name') or rec_id), ('state', '=', 'done'), ('move_id.returned_move_ids', '=', False), ]) @@ -114,7 +114,8 @@ class MrpStockReport(models.TransientModel): 'model_id': move_line.id, 'model':'stock.move.line', 'product_id': move_line.product_id.display_name, - 'lot_id': move_line.lot_id.name, + 'lot_name': move_line.lot_id.name, + 'lot_id': move_line.lot_id.id, 'product_qty_uom': str(move_line.product_uom_id._compute_quantity(move_line.qty_done, move_line.product_id.uom_id, rounding_method='HALF-UP')) + ' ' + move_line.product_id.uom_id.name, 'location_source': move_line.location_id.name, 'location_destination': move_line.location_dest_id.name, @@ -136,7 +137,8 @@ class MrpStockReport(models.TransientModel): 'parent_id': parent_id, 'model': model or 'stock.move.line', 'product_id': move_line.product_id.display_name, - 'lot_id': move_line.lot_id.name, + 'lot_name': move_line.lot_id.name, + 'lot_id': move_line.lot_id.id, 'product_qty_uom': str(move_line.product_uom_id._compute_quantity(move_line.qty_done, move_line.product_id.uom_id, rounding_method='HALF-UP')) + ' ' + move_line.product_id.uom_id.name, 'location_source': move_line.location_id.name if not move_line.lot_id else False, 'location_destination': move_line.location_dest_id.name if not move_line.lot_id else False, @@ -156,16 +158,17 @@ class MrpStockReport(models.TransientModel): 'parent_id': data['parent_id'], 'usage': data.get('usage', False), 'is_used': data.get('is_used', False), + 'lot_name': data.get('lot_name', False), 'lot_id': data.get('lot_id', False), 'type': 'line', 'reference': data.get('reference_id', False), 'res_id': data.get('res_id', False), 'res_model': data.get('res_model', False), - 'name': _(data.get('lot_id', False)), + 'name': _(data.get('lot_name', False)), 'columns': [data.get('reference_id', False), data.get('product_id', False), data.get('date', False), - data.get('lot_id', False), + data.get('lot_name', False), data.get('location_source', False), data.get('location_destination', False), data.get('product_qty_uom', 0)], @@ -223,11 +226,11 @@ class MrpStockReport(models.TransientModel): 'model_id': data['model_id'], 'parent_id': data['parent_id'], 'type': 'line', - 'name': _(data.get('lot_id')), + 'name': _(data.get('lot_name')), 'columns': [data.get('reference_id'), data.get('product_id'), data.get('date'), - data.get('lot_id'), + data.get('lot_name'), data.get('location_source', False), data.get('location_destination', False), data.get('product_qty_uom', 0)], diff --git a/addons/stock/static/src/js/stock_traceability_report_backend.js b/addons/stock/static/src/js/stock_traceability_report_backend.js index 472bd93ff04..553c155e94a 100644 --- a/addons/stock/static/src/js/stock_traceability_report_backend.js +++ b/addons/stock/static/src/js/stock_traceability_report_backend.js @@ -24,7 +24,7 @@ var stock_report_generic = Widget.extend(ControlPanelMixin, { this.given_context.model = action.context.active_model || false; this.given_context.ttype = action.context.ttype || false; this.given_context.auto_unfold = action.context.auto_unfold || false; - this.given_context.lot_id = action.context.lot_id || false; + this.given_context.lot_name = action.context.lot_name || false; return this._super.apply(this, arguments); }, willStart: function() { @@ -42,7 +42,7 @@ var stock_report_generic = Widget.extend(ControlPanelMixin, { self.report_widget.$el.find('.o_report_heading').html('

Traceability Report

') if (self.given_context.auto_unfold) { _.each(self.$el.find('.fa-caret-right'), function (line) { - self.report_widget.autounfold(line, self.given_context.lot_id); + self.report_widget.autounfold(line, self.given_context.lot_name); }); } }); diff --git a/addons/stock/static/src/js/stock_traceability_report_widgets.js b/addons/stock/static/src/js/stock_traceability_report_widgets.js index 187f229b868..ea08871828f 100644 --- a/addons/stock/static/src/js/stock_traceability_report_widgets.js +++ b/addons/stock/static/src/js/stock_traceability_report_widgets.js @@ -34,13 +34,12 @@ var ReportWidget = Widget.extend({ }, actionOpenLot: function(e) { var $el = $(e.target).parents('tr'); - var lot_id = $el.data('lot_id'); this.do_action({ type: 'ir.actions.client', tag: 'stock_report_generic', - name: $el.data('lot_id'), + name: $el.data('lot_name'), context: { - active_id : lot_id, + active_id : $el.data('lot_id'), active_model : 'stock.production.lot', url: '/stock/output_format/stock/active_id' }, @@ -49,7 +48,6 @@ var ReportWidget = Widget.extend({ updownStream: function(e) { var $el = $(e.target).parents('tr'); var string = "Traceability Report"; - console.log($el.data('lot_id')); this.do_action({ type: "ir.actions.client", tag: 'stock_report_generic', @@ -58,7 +56,7 @@ var ReportWidget = Widget.extend({ active_id : $el.data('model_id'), active_model : $el.data('model'), auto_unfold: true, - lot_id: $el.data('lot_id') !== undefined && $el.data('lot_id').toString(), + lot_name: $el.data('lot_name') !== undefined && $el.data('lot_name').toString(), url: '/stock/output_format/stock/active_id' }, }); @@ -89,7 +87,7 @@ var ReportWidget = Widget.extend({ $(e.target).parents('tr').find('span.o_stock_reports_foldable').replaceWith(QWeb.render("unfoldable", {lineId: active_id})); $(e.target).parents('tr').toggleClass('o_stock_reports_unfolded'); }, - autounfold: function(target, lot_id) { + autounfold: function(target, lot_name) { var self = this; var $CurretElement; $CurretElement = $(target).parents('tr').find('td.o_stock_reports_unfoldable'); @@ -112,8 +110,8 @@ var ReportWidget = Widget.extend({ _.each(lines, function (line) { // Render each line $cursor.after(QWeb.render("report_mrp_line", {l: line})); $cursor = $cursor.next(); - if ($cursor && line.unfoldable && line.lot_id == lot_id) { - self.autounfold($cursor.find(".fa-caret-right"), lot_id); + if ($cursor && line.unfoldable && line.lot_name == lot_name) { + self.autounfold($cursor.find(".fa-caret-right"), lot_name); } }); }); diff --git a/addons/stock/static/src/xml/stock_traceability_report_line.xml b/addons/stock/static/src/xml/stock_traceability_report_line.xml index 1a4cc85fdc1..f8778dff2ab 100644 --- a/addons/stock/static/src/xml/stock_traceability_report_line.xml +++ b/addons/stock/static/src/xml/stock_traceability_report_line.xml @@ -24,12 +24,12 @@ - + - + @@ -41,7 +41,12 @@ - + + + + + + diff --git a/addons/stock/views/report_stock_traceability.xml b/addons/stock/views/report_stock_traceability.xml index d4800eac77c..b8030f818a9 100644 --- a/addons/stock/views/report_stock_traceability.xml +++ b/addons/stock/views/report_stock_traceability.xml @@ -10,7 +10,7 @@ - + @@ -36,8 +36,8 @@ - - + +