[ADD] BoM price report

In v8, we had a BoM price report in xsl format which was removed in v9.

As it is still needed, we added a report in the new qweb format, but this
time it is on the BoM instead of the product variant.

It also makes sense to have a similar report for v10 as the cost structure report
on the mo is for the real cost and not the standard cost.
This commit is contained in:
Josse Colpaert
2016-07-06 10:34:29 +02:00
parent 3f3c30887c
commit f719d76fed
5 changed files with 113 additions and 1 deletions
+1
View File
@@ -48,6 +48,7 @@ Dashboard / Reports for MRP will include:
'res_config_view.xml',
'views/report_mrporder.xml',
'views/report_mrpbomstructure.xml',
'views/report_mrpbomcost.xml',
],
'demo': ['mrp_demo.xml'],
'test': [
+8 -1
View File
@@ -18,6 +18,13 @@
file="mrp.report_mrporder"
report_type="qweb-pdf"
/>
<report
string="BOM Cost"
id="action_report_bom_price"
model="mrp.bom"
name="mrp_bom_cost"
file="mrp_bom_cost"
report_type="qweb-pdf"
/>
</data>
</openerp>
+1
View File
@@ -3,3 +3,4 @@
import bom_structure
import mrp_report
import bom_cost
+48
View File
@@ -0,0 +1,48 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from openerp import api, models
class MrpBomCost(models.AbstractModel):
_name = 'report.mrp_bom_cost'
@api.multi
def get_lines(self, boms):
product_lines = []
for bom in boms:
products = bom.product_id
if not products:
products = bom.product_tmpl_id.product_variant_ids
for product in products:
attributes = []
for value in product.attribute_value_ids:
attributes += [(value.attribute_id.name, value.name)]
result, result2 = self.env['mrp.bom']._bom_explode(bom, product, 1)
product_line = {'name': product.name, 'lines': [], 'total': 0.0,
'currency': self.env.user.company_id.currency_id,
'product_uom_qty': bom.product_qty,
'product_uom': bom.product_uom,
'attributes': attributes}
total = 0.0
for bom_line in result:
line_product = self.env['product.product'].browse(bom_line['product_id'])
price_uom = self.env['product.uom']._compute_qty(line_product.uom_id.id, line_product.standard_price, bom_line['product_uom'])
line = {
'product_id': line_product,
'product_uom_qty': bom_line['product_qty'],
'product_uom': self.env['product.uom'].browse(bom_line['product_uom']),
'price_unit': price_uom,
'total_price': price_uom * bom_line['product_qty'],
}
total += line['total_price']
product_line['lines'] += [line]
product_line['total'] = total
product_lines += [product_line]
return product_lines
@api.multi
def render_html(self, data=None):
boms = self.env['mrp.bom'].browse(self.ids)
res = self.get_lines(boms)
return self.env['report'].render('mrp.mrp_bom_cost', {'lines': res})
+55
View File
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="mrp_bom_cost">
<div class="o_form_view">
<div class="page o_form_sheet_bg">
<div class="o_form_sheet">
<t t-foreach="lines" t-as="line">
<t t-set="currency" t-value="line['currency']"/>
<table class="table table-condensed">
<thead>
<tr>
<th colspan="6">
<h1><t t-esc="line['name']"/></h1><br/>
<b><t t-esc="line['product_uom_qty']"/> <t t-esc="line['product_uom'].name"/></b>
<table>
<tbody>
<tr t-foreach="line['attributes']" t-as="attrib">
<td><span t-esc="attrib[0]"/></td>
<td><span t-esc="attrib[1]"/></td>
</tr>
</tbody>
</table>
<h2>Cost Structure</h2>
</th>
</tr>
<tr>
<th colspan="2">Raw Materials</th>
<th class="col-sm-2 text-right">Quantity</th>
<th class="col-sm-2 text-right">Unit Cost</th>
<th class="col-sm-2 text-right">Total Cost</th>
</tr>
</thead>
<tbody>
<tr t-foreach="line['lines']" t-as="bom_line">
<td colspan="2">
<span t-esc="bom_line['product_id'].name"/>
</td>
<td class="text-right">
<span t-esc="bom_line['product_uom_qty']"/> <span t-esc="bom_line['product_uom'].name" groups="product.group_uom"/>
</td>
<td class="text-right"><span t-esc="bom_line['price_unit']" t-esc-options='{"widget": "monetary", "display_currency": "currency"}'/></td>
<td class="text-right"><span t-esc="bom_line['total_price']" t-esc-options='{"widget": "monetary", "display_currency": "currency"}'/></td>
</tr>
<tr>
<th colspan="4" class="text-right">Total Cost of Raw Materials</th>
<th class="text-right"><t t-esc="line['total']" t-esc-options='{"widget": "monetary", "display_currency": "currency"}'/></th>
</tr>
</tbody>
</table>
</t>
</div>
</div>
</div>
</template>
</odoo>