From f719d76fed2687bad6e553096ce39f26d1f4b0af Mon Sep 17 00:00:00 2001 From: Josse Colpaert Date: Mon, 13 Jun 2016 23:05:20 +0200 Subject: [PATCH] [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. --- addons/mrp/__openerp__.py | 1 + addons/mrp/mrp_report.xml | 9 ++++- addons/mrp/report/__init__.py | 1 + addons/mrp/report/bom_cost.py | 48 ++++++++++++++++++++++ addons/mrp/views/report_mrpbomcost.xml | 55 ++++++++++++++++++++++++++ 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 addons/mrp/report/bom_cost.py create mode 100644 addons/mrp/views/report_mrpbomcost.xml diff --git a/addons/mrp/__openerp__.py b/addons/mrp/__openerp__.py index b405f402d81..efcdb5f73c3 100644 --- a/addons/mrp/__openerp__.py +++ b/addons/mrp/__openerp__.py @@ -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': [ diff --git a/addons/mrp/mrp_report.xml b/addons/mrp/mrp_report.xml index 903749cf1a3..5c93b996207 100644 --- a/addons/mrp/mrp_report.xml +++ b/addons/mrp/mrp_report.xml @@ -18,6 +18,13 @@ file="mrp.report_mrporder" report_type="qweb-pdf" /> - + diff --git a/addons/mrp/report/__init__.py b/addons/mrp/report/__init__.py index a71fee4bbc2..73a73053af1 100644 --- a/addons/mrp/report/__init__.py +++ b/addons/mrp/report/__init__.py @@ -3,3 +3,4 @@ import bom_structure import mrp_report +import bom_cost \ No newline at end of file diff --git a/addons/mrp/report/bom_cost.py b/addons/mrp/report/bom_cost.py new file mode 100644 index 00000000000..d27a05b1bce --- /dev/null +++ b/addons/mrp/report/bom_cost.py @@ -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}) \ No newline at end of file diff --git a/addons/mrp/views/report_mrpbomcost.xml b/addons/mrp/views/report_mrpbomcost.xml new file mode 100644 index 00000000000..3237e55c47a --- /dev/null +++ b/addons/mrp/views/report_mrpbomcost.xml @@ -0,0 +1,55 @@ + + + +