diff --git a/addons/mrp/report/mrp_report_bom_structure.py b/addons/mrp/report/mrp_report_bom_structure.py index 7af40fcb785..b66805f8eef 100644 --- a/addons/mrp/report/mrp_report_bom_structure.py +++ b/addons/mrp/report/mrp_report_bom_structure.py @@ -34,6 +34,7 @@ class ReportBomStructure(models.AbstractModel): res = self._get_report_data(bom_id=bom_id, searchQty=searchQty, searchVariant=searchVariant) res['lines']['report_type'] = 'html' res['lines']['report_structure'] = 'all' + res['lines']['has_attachments'] = res['lines']['attachments'] or any(component['attachments'] for component in res['lines']['components']) res['lines'] = self.env.ref('mrp.report_mrp_bom').render({'data': res['lines']}) return res @@ -70,7 +71,6 @@ class ReportBomStructure(models.AbstractModel): bom_product_variants[variant.id] = variant.display_name lines = self._get_bom(bom_id, product_id=searchVariant, line_qty=bom_quantity, level=1) - return { 'lines': lines, 'variants': bom_product_variants, @@ -103,6 +103,8 @@ class ReportBomStructure(models.AbstractModel): 'level': level or 0, 'operations': operations, 'operations_cost': sum([op['total'] for op in operations]), + 'attachments': self.env['mrp.document'].search(['|', '&', + ('res_model', '=', 'product.product'), ('res_id', '=', product.id), '&', ('res_model', '=', 'product.template'), ('res_id', '=', product.product_tmpl_id.id)]), 'operations_time': sum([op['duration_expected'] for op in operations]) } components, total = self._get_bom_lines(bom, bom_quantity, product, line_id, level) @@ -135,6 +137,9 @@ class ReportBomStructure(models.AbstractModel): 'total': sub_total, 'child_bom': line.child_bom_id.id, 'phantom_bom': line.child_bom_id and line.child_bom_id.type == 'phantom' or False, + 'attachments': self.env['mrp.document'].search(['|', '&', + ('res_model', '=', 'product.product'), ('res_id', '=', line.product_id.id), '&', ('res_model', '=', 'product.template'), ('res_id', '=', line.product_id.product_tmpl_id.id)]), + }) total += sub_total return components, total diff --git a/addons/mrp/report/mrp_report_bom_structure.xml b/addons/mrp/report/mrp_report_bom_structure.xml index 8cdb1a8940e..b607c146f22 100644 --- a/addons/mrp/report/mrp_report_bom_structure.xml +++ b/addons/mrp/report/mrp_report_bom_structure.xml @@ -28,6 +28,7 @@ Unit of Measure Product Cost BoM Cost + Attachments @@ -43,6 +44,13 @@ + + + + + + + @@ -96,6 +104,13 @@ + + + + + + + @@ -115,6 +130,7 @@ + @@ -136,6 +152,7 @@ + diff --git a/addons/mrp/static/src/js/mrp_bom_report.js b/addons/mrp/static/src/js/mrp_bom_report.js index 326275cbe71..82c634b468e 100644 --- a/addons/mrp/static/src/js/mrp_bom_report.js +++ b/addons/mrp/static/src/js/mrp_bom_report.js @@ -6,12 +6,14 @@ var framework = require('web.framework'); var stock_report_generic = require('stock.stock_report_generic'); var QWeb = core.qweb; +var _t = core._t; var MrpBomReport = stock_report_generic.extend({ events: { 'click .o_mrp_bom_unfoldable': '_onClickUnfold', 'click .o_mrp_bom_foldable': '_onClickFold', 'click .o_mrp_bom_action': '_onClickAction', + 'click .o_mrp_show_attachment_action': '_onClickShowAttachment', }, get_html: function() { var self = this; @@ -38,6 +40,16 @@ var MrpBomReport = stock_report_generic.extend({ }); }, render_html: function(event, $el, result){ + if (result.indexOf('mrp.document') > 0) { + if (this.$('.o_mrp_has_attachments').length === 0) { + var column = $('', { + class: 'o_mrp_has_attachments', + title: 'Files attached to the product Attachments', + text: 'Attachments', + }); + this.$('table thead th:last-child').after(column); + } + } $el.after(result); $(event.currentTarget).toggleClass('o_mrp_bom_foldable o_mrp_bom_unfoldable fa-caret-right fa-caret-down'); this._reload_report_type(); @@ -58,7 +70,7 @@ var MrpBomReport = stock_report_generic.extend({ productID, parseFloat(qty), lineID, - level + 1 + level + 1, ] }) .then(function (result) { @@ -159,6 +171,18 @@ var MrpBomReport = stock_report_generic.extend({ target: 'current' }); }, + _onClickShowAttachment: function (ev) { + var ids = $(ev.currentTarget).data('res-id'); + return this.do_action({ + name: _t('Attachments'), + type: 'ir.actions.act_window', + res_model: $(ev.currentTarget).data('model'), + domain: [['id', 'in', ids]], + views: [[false, 'kanban'], [false, 'list'], [false, 'form']], + view_mode: 'kanban,list,form', + target: 'current', + }); + }, _reload: function () { var self = this; return this.get_html().then(function () {