diff --git a/addons/mrp/report/mrp_report_bom_structure.py b/addons/mrp/report/mrp_report_bom_structure.py index ccc2067af3934bda67c042d91c9db8c83308d1f9..db8eb097fd45ac6c833af39db24b97eec0eef58d 100644 --- a/addons/mrp/report/mrp_report_bom_structure.py +++ b/addons/mrp/report/mrp_report_bom_structure.py @@ -16,7 +16,7 @@ class ReportBomStructure(models.AbstractModel): bom = self.env['mrp.bom'].browse(bom_id) candidates = bom.product_id or bom.product_tmpl_id.product_variant_ids quantity = float(data.get('quantity', 1)) - for product_variant_id in candidates: + for product_variant_id in candidates.ids: if data and data.get('childs'): doc = self._get_pdf_line(bom_id, product_id=product_variant_id, qty=quantity, child_bom_ids=json.loads(data.get('childs'))) else: @@ -91,6 +91,7 @@ class ReportBomStructure(models.AbstractModel): def _get_bom(self, bom_id=False, product_id=False, line_qty=False, line_id=False, level=False): bom = self.env['mrp.bom'].browse(bom_id) + company = bom.company_id or self.env.company bom_quantity = line_qty if line_id: current_line = self.env['mrp.bom.line'].browse(int(line_id)) @@ -101,15 +102,16 @@ class ReportBomStructure(models.AbstractModel): else: product = bom.product_id or bom.product_tmpl_id.product_variant_id if product: + price = product.uom_id._compute_price(product.with_context(force_company=company.id).standard_price, bom.product_uom_id) * bom_quantity 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)]) else: - product = bom.product_tmpl_id - attachments = self.env['mrp.document'].search([('res_model', '=', 'product.template'), ('res_id', '=', product.id)]) + # Use the product template instead of the variant + price = bom.product_tmpl_id.uom_id._compute_price(bom.product_tmpl_id.with_context(force_company=company.id).standard_price, bom.product_uom_id) * bom_quantity + attachments = self.env['mrp.document'].search([('res_model', '=', 'product.template'), ('res_id', '=', bom.product_tmpl_id.id)]) operations = [] if bom.product_qty > 0: operations = self._get_operation_line(bom.routing_id, float_round(bom_quantity / bom.product_qty, precision_rounding=1, rounding_method='UP'), 0) - company = bom.company_id or self.env.company lines = { 'bom': bom, 'bom_qty': bom_quantity, @@ -117,7 +119,7 @@ class ReportBomStructure(models.AbstractModel): 'currency': company.currency_id, 'product': product, 'code': bom and bom.display_name or '', - 'price': product.uom_id._compute_price(product.with_context(force_company=company.id).standard_price, bom.product_uom_id) * bom_quantity, + 'price': price, 'total': sum([op['total'] for op in operations]), 'level': level or 0, 'operations': operations, @@ -211,7 +213,7 @@ class ReportBomStructure(models.AbstractModel): def _get_pdf_line(self, bom_id, product_id=False, qty=1, child_bom_ids=[], unfolded=False): def get_sub_lines(bom, product_id, line_qty, line_id, level): - data = self._get_bom(bom_id=bom.id, product_id=product_id.id, line_qty=line_qty, line_id=line_id, level=level) + data = self._get_bom(bom_id=bom.id, product_id=product_id, line_qty=line_qty, line_id=line_id, level=level) bom_lines = data['components'] lines = [] for bom_line in bom_lines: @@ -229,7 +231,7 @@ class ReportBomStructure(models.AbstractModel): }) if bom_line['child_bom'] and (unfolded or bom_line['child_bom'] in child_bom_ids): line = self.env['mrp.bom.line'].browse(bom_line['line_id']) - lines += (get_sub_lines(line.child_bom_id, line.product_id, bom_line['prod_qty'], line, level + 1)) + lines += (get_sub_lines(line.child_bom_id, line.product_id.id, bom_line['prod_qty'], line, level + 1)) if data['operations']: lines.append({ 'name': _('Operations'), @@ -252,9 +254,9 @@ class ReportBomStructure(models.AbstractModel): return lines bom = self.env['mrp.bom'].browse(bom_id) - product = product_id or bom.product_id or bom.product_tmpl_id.product_variant_id - data = self._get_bom(bom_id=bom_id, product_id=product.id, line_qty=qty) - pdf_lines = get_sub_lines(bom, product, qty, False, 1) + product_id = product_id or bom.product_id.id or bom.product_tmpl_id.product_variant_id.id + data = self._get_bom(bom_id=bom_id, product_id=product_id, line_qty=qty) + pdf_lines = get_sub_lines(bom, product_id, qty, False, 1) data['components'] = [] data['lines'] = pdf_lines return data