[IMP] mrp: show product attachments in bom structure and cost report

Show all the documents related to products in the Bom Structure and costs report.
On click of the icon attachments, open all the documents/attachments related to product
and its template.

Task id : 1857701.
This commit is contained in:
Hetashree Chauhan
2018-08-09 11:13:00 +02:00
committed by Arnold Moyaux
parent c9e132ea43
commit 88bf279c46
3 changed files with 48 additions and 2 deletions
@@ -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
@@ -28,6 +28,7 @@
<th groups="uom.group_uom">Unit of Measure</th>
<th t-if="data['report_structure'] != 'bom_cost'" class="o_mrp_prod_cost" title="This is the cost defined on the product.">Product Cost</th>
<th t-if="data['report_structure'] != 'bom_structure'" class="o_mrp_bom_cost" title="This is the cost based on the BoM of the product. It is computed by summing the costs of the components and operations needed to build the product.">BoM Cost</th>
<th t-if="data['report_type'] == 'html' and data['has_attachments']" class="o_mrp_has_attachments" title="Files attached to the product">Attachments</th>
</tr>
</thead>
<tbody>
@@ -43,6 +44,13 @@
<td t-if="data['report_structure'] != 'bom_structure'" class="o_mrp_bom_cost">
<span><t t-esc="data['total']" t-options='{"widget": "monetary", "display_currency": currency}'/></span>
</td>
<td t-if="data['report_type'] == 'html'">
<span>
<t t-if="data['attachments']">
<a role="button" t-att-data-res-id="data['attachments'].ids" t-att-data-model="'mrp.document'" class="o_mrp_show_attachment_action fa fa-fw o_button_icon fa-files-o"/>
</t>
</span>
</td>
</tr>
<t t-if="data['report_type'] == 'html'" t-call="mrp.report_mrp_bom_line"/>
<t t-if="data['report_type'] == 'pdf'" t-call="mrp.report_mrp_bom_pdf_line"/>
@@ -96,6 +104,13 @@
<td class="o_mrp_bom_cost">
<span t-esc="l['total']" t-options='{"widget": "monetary", "display_currency": currency}'/>
</td>
<td>
<span>
<t t-if="l['attachments']">
<a role="button" t-att-data-res-id="l['attachments'].ids" t-att-data-model="'mrp.document'" class="o_mrp_show_attachment_action fa fa-fw o_button_icon fa-files-o"/>
</t>
</span>
</td>
</tr>
</t>
<t t-if="data['operations']">
@@ -115,6 +130,7 @@
<td class="o_mrp_bom_cost">
<span t-esc="data['operations_cost']" t-options='{"widget": "monetary", "display_currency": currency}'/>
</td>
<td/>
</tr>
</t>
</template>
@@ -136,6 +152,7 @@
<td class="o_mrp_bom_cost">
<span t-esc="op['total']" t-options='{"widget": "monetary", "display_currency": currency}'/>
</td>
<td/>
</tr>
</t>
</template>
+25 -1
View File
@@ -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 = $('<th/>', {
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 () {