From 4b1a1c132bdae288195e43728a25ae0d860fc704 Mon Sep 17 00:00:00 2001 From: jayraj-omnia Date: Wed, 29 Jan 2025 19:33:25 +0530 Subject: [PATCH] [ADD] add product change impact report --- plm/__manifest__.py | 1 + plm/controllers/main.py | 7 + plm/data/data.xml | 22 ++ plm/models/product_product.py | 9 + plm/report/__init__.py | 3 +- plm/report/bom_document.xml | 22 +- plm/report/product_change_impact_report.py | 38 +++ plm/report/product_change_impact_template.xml | 236 ++++++++++++++++++ 8 files changed, 325 insertions(+), 13 deletions(-) create mode 100644 plm/report/product_change_impact_report.py create mode 100644 plm/report/product_change_impact_template.xml diff --git a/plm/__manifest__.py b/plm/__manifest__.py index a4a644e5..c43a0c34 100644 --- a/plm/__manifest__.py +++ b/plm/__manifest__.py @@ -33,6 +33,7 @@ "depends": ["base", "board", "product", "mrp"], "data": [ "security/base_plm_security.xml", + "report/product_change_impact_template.xml", "data/data.xml", "data/sequence.xml", "report/bom_document.xml", diff --git a/plm/controllers/main.py b/plm/controllers/main.py index 4c8f68c4..4b94ac34 100755 --- a/plm/controllers/main.py +++ b/plm/controllers/main.py @@ -267,6 +267,13 @@ def get_preview(self, id): for record in ir_attachement.search_read([('id','=', id)], ['preview']): return base64.b64decode(record.get('preview')) + @route('/plm/product_product_image_1920/', type='http', auth='user', methods=['GET'], csrf=False) + @webservice + def get_product_preview(self, id): + productobj = request.env['product.product'].sudo() + for record in productobj.search_read([('id', '=', id)], ['image_1920']): + return base64.b64decode(record.get('image_1920')) + @route('/plm/product_product_preview/', type='http', auth='user', methods=['GET'], csrf=False) @webservice def get_pp_preview(self, product_id): diff --git a/plm/data/data.xml b/plm/data/data.xml index 8e15170d..fd05c575 100644 --- a/plm/data/data.xml +++ b/plm/data/data.xml @@ -9,5 +9,27 @@ 200 request + + + + Check Change Impact + + + form + code + action = records.check_product_change_impact() + + + + + Product Change Impact + product.product + qweb-html + + plm.product_change_impact_report_template + plm.product_change_impact_report_template + 'product : %s Change Impact' % (object.display_name) + + diff --git a/plm/models/product_product.py b/plm/models/product_product.py index bdd2f74e..c35166a5 100755 --- a/plm/models/product_product.py +++ b/plm/models/product_product.py @@ -59,6 +59,15 @@ class ProductProduct(models.Model): _inherit = ['product.product'] _description ="Product Product" + def check_product_change_impact(self): + self.ensure_one() + report_data = {} + bomobj = self.env['mrp.bom'] + rel_datas, prt_datas, relation_datas = bomobj.get_where_used([self.id]) + report_data["active_id"] = self.id + report_data["prt_datas"] = prt_datas + return self.env.ref('plm.action_report_product_change_impact').report_action(docids=[self.id], data=report_data) + def onchange(self, values, field_names, fields_spec): values = self.plm_sanitize(values) if 'product_tmpl_id' in values: diff --git a/plm/report/__init__.py b/plm/report/__init__.py index af1c9753..6379fd69 100755 --- a/plm/report/__init__.py +++ b/plm/report/__init__.py @@ -24,7 +24,6 @@ from . import product_report_document from . import bom_structure from . import mrp_report_bom_structure - - +from . import product_change_impact_report #import new_reports # To Delete when reports are working diff --git a/plm/report/bom_document.xml b/plm/report/bom_document.xml index d187aabd..ef597d55 100644 --- a/plm/report/bom_document.xml +++ b/plm/report/bom_document.xml @@ -54,9 +54,9 @@
-
+
- + @@ -69,7 +69,7 @@
- + - + - + Paperformat Doc Structure @@ -172,7 +172,7 @@
- + Document structure ir.attachment @@ -185,4 +185,4 @@ report - \ No newline at end of file + diff --git a/plm/report/product_change_impact_report.py b/plm/report/product_change_impact_report.py new file mode 100644 index 00000000..fcf2d78d --- /dev/null +++ b/plm/report/product_change_impact_report.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +from odoo import api, models + + +class HrHolidaySummaryReport(models.AbstractModel): + _name = 'report.plm.product_change_impact_report_template' + _description = 'product change impact report' + + @api.model + def _get_report_values(self, docids, data=None): + productobj = self.env['product.product'] + attachmentobj = self.env['ir.attachment'] + bomobj = self.env['mrp.bom'] + + product_change_impact_report = self.env['ir.actions.report']._get_report_from_name('plm.product_change_impact_report_template') + if data: + affect_product_ids = [] + affect_attachment_ids = [] + affect_bom_ids = [] + prt_datas = data.get("prt_datas", {}) + product_id = productobj.browse(data['active_id']) + for product_data in prt_datas: + affect_product_ids.append(productobj.browse(prt_datas[product_data].get("id"))) + affect_attachment_ids.extend(attachmentobj.browse(prt_datas[product_data].get("linkeddocuments", []))) + affect_bom_ids.extend(bomobj.browse(prt_datas[product_data].get("bom_ids", []))) + + return { + 'doc_ids': product_id, + 'doc_model': product_change_impact_report.model, + 'affect_product_ids': affect_product_ids, + 'affect_attachment_ids': affect_attachment_ids, + 'affect_bom_ids': affect_bom_ids, + } + + return { + 'doc_ids': docids, + 'doc_model': product_change_impact_report.model, + } diff --git a/plm/report/product_change_impact_template.xml b/plm/report/product_change_impact_template.xml new file mode 100644 index 00000000..498ce0f5 --- /dev/null +++ b/plm/report/product_change_impact_template.xml @@ -0,0 +1,236 @@ + + + +