From 77e1105e1df1ab1f6dc06d42e2c92a3068d4ab08 Mon Sep 17 00:00:00 2001 From: jayraj-omnia Date: Fri, 31 Jan 2025 15:59:19 +0530 Subject: [PATCH] [ADD] change impact report for attachemt --- plm/__manifest__.py | 8 +- plm/data/data.xml | 23 +- plm/models/ir_attachment.py | 10 + plm/report/__init__.py | 1 + .../attachment_change_impact_template.py | 47 + .../attachment_change_impact_template.xml | 556 +++++++++++ plm/report/product_change_impact_report.py | 13 +- plm/report/product_change_impact_template.xml | 894 +++++++----------- 8 files changed, 1006 insertions(+), 546 deletions(-) create mode 100644 plm/report/attachment_change_impact_template.py create mode 100644 plm/report/attachment_change_impact_template.xml diff --git a/plm/__manifest__.py b/plm/__manifest__.py index c43a0c34..7afa14cb 100644 --- a/plm/__manifest__.py +++ b/plm/__manifest__.py @@ -33,17 +33,19 @@ "depends": ["base", "board", "product", "mrp"], "data": [ "security/base_plm_security.xml", - "report/product_change_impact_template.xml", + "report/product_report_document.xml", + "report/bom_document.xml", + "data/data.xml", "data/sequence.xml", - "report/bom_document.xml", "report/bom_structure_report_template.xml", "report/document_report_templates.xml", "report/product_report_templates.xml", - "report/product_report_document.xml", "report/bom_structure.xml", "report/component_report.xml", "report/document_report.xml", + "report/product_change_impact_template.xml", + "report/attachment_change_impact_template.xml", "views/product_product_first.xml", "views/ir_attachment_view.xml", "views/ir_attachment_relations.xml", diff --git a/plm/data/data.xml b/plm/data/data.xml index fd05c575..b552a3bc 100644 --- a/plm/data/data.xml +++ b/plm/data/data.xml @@ -12,7 +12,7 @@ - Check Change Impact + Check Product Change Impact form @@ -31,5 +31,26 @@ 'product : %s Change Impact' % (object.display_name) + + + Check Attachment Change Impact + + + form + code + action = records.check_attachment_change_impact() + + + + + Attachment Change Impact + ir.attachment + qweb-html + + plm.attachment_change_impact_report_template + plm.attachment_change_impact_report_template + 'attachment : %s change impact report' % (object.display_name) + + diff --git a/plm/models/ir_attachment.py b/plm/models/ir_attachment.py index aac76d72..4b1cc087 100755 --- a/plm/models/ir_attachment.py +++ b/plm/models/ir_attachment.py @@ -3284,4 +3284,14 @@ def CheckInById(self, doc_id): return docBrws.id return False + def check_attachment_change_impact(self): + self.ensure_one() + report_data = {} + report_data["active_id"] = self.id + + return self.env.ref( + 'plm.action_report_attachment_change_impact' + ).report_action(docids=[self.id], + data=report_data) + # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/plm/report/__init__.py b/plm/report/__init__.py index 6379fd69..f551d40a 100755 --- a/plm/report/__init__.py +++ b/plm/report/__init__.py @@ -25,5 +25,6 @@ from . import bom_structure from . import mrp_report_bom_structure from . import product_change_impact_report +from . import attachment_change_impact_template #import new_reports # To Delete when reports are working diff --git a/plm/report/attachment_change_impact_template.py b/plm/report/attachment_change_impact_template.py new file mode 100644 index 00000000..3b140c56 --- /dev/null +++ b/plm/report/attachment_change_impact_template.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +from odoo import api, models + + +class ProductChangeImpactReport(models.AbstractModel): + _name = 'report.plm.attachment_change_impact_report_template' + _description = 'attachment change impact report' + + def get_product_hierarchy(self, product_id, level=0): + + product = self.env['product.product'].browse(product_id) + hierarchy = {"level": level, "product": product, "children": []} + + bom_lines = self.env['mrp.bom.line'].search([('product_id', '=', product.id)]) + for bom_line in bom_lines: + parent_product = bom_line.bom_id.product_tmpl_id.product_variant_id + parent_hierarchy = self.get_product_hierarchy(parent_product.id, level + 1) + hierarchy["children"].append(parent_hierarchy) + + return hierarchy + + @api.model + def _get_report_values(self, docids, data=None): + attachment_change_impact_report = self.env[ + 'ir.actions.report' + ]._get_report_from_name('plm.attachment_change_impact_report_template') + + if data and "active_id" in data: + attachment_obj = self.env['ir.attachment'] + attachment_id = attachment_obj.browse(data['active_id']) + + linked_product = attachment_id.linkedcomponents + + product_data = [] + for product in linked_product: + product_data.append(self.get_product_hierarchy(product_id=product.id)) + + return { + 'doc_ids': docids, + 'doc_model': attachment_change_impact_report.model, + 'product_data': product_data + } + + return { + 'doc_ids': docids, + 'doc_model': attachment_change_impact_report.model, + } diff --git a/plm/report/attachment_change_impact_template.xml b/plm/report/attachment_change_impact_template.xml new file mode 100644 index 00000000..b4fbbb35 --- /dev/null +++ b/plm/report/attachment_change_impact_template.xml @@ -0,0 +1,556 @@ + + + + diff --git a/plm/report/product_change_impact_report.py b/plm/report/product_change_impact_report.py index f9990977..cc0255ed 100644 --- a/plm/report/product_change_impact_report.py +++ b/plm/report/product_change_impact_report.py @@ -6,19 +6,12 @@ class ProductChangeImpactReport(models.AbstractModel): _name = 'report.plm.product_change_impact_report_template' _description = 'product change impact report' - def get_bom_hierarchy(self, product_id, level=0, direction="child"): + def get_bom_hierarchy(self, product_id, level=0, direction="parent"): product = self.env['product.product'].browse(product_id) hierarchy = {"level": level, "product": product, "children": []} - if direction == "child": - boms = self.env['mrp.bom'].search([('product_tmpl_id', '=', product.product_tmpl_id.id)]) - for bom in boms: - for line in bom.bom_line_ids: - sub_hierarchy = self.get_bom_hierarchy(line.product_id.id, level + 1, direction) - hierarchy["children"].append(sub_hierarchy) - - elif direction == "parent": + if direction == "parent": bom_lines = self.env['mrp.bom.line'].search([('product_id', '=', product.id)]) for bom_line in bom_lines: parent_product = bom_line.bom_id.product_tmpl_id.product_variant_id @@ -38,7 +31,6 @@ def _get_report_values(self, docids, data=None): prt_datas = data.get("prt_datas", {}) product_id = productobj.browse(data['active_id']) - hierarchy_child = self.get_bom_hierarchy(product_id=data['active_id'], level=0, direction="child") hierarchy_parent = self.get_bom_hierarchy(product_id=data['active_id'], level=0, direction="parent") for product_data in prt_datas: @@ -47,7 +39,6 @@ def _get_report_values(self, docids, data=None): return { 'doc_ids': product_id, 'doc_model': product_change_impact_report.model, - 'hierarchy_child': hierarchy_child, 'hierarchy_parent': hierarchy_parent, 'affect_attachment_ids': affect_attachment_ids, } diff --git a/plm/report/product_change_impact_template.xml b/plm/report/product_change_impact_template.xml index 82e60a37..722a122e 100644 --- a/plm/report/product_change_impact_template.xml +++ b/plm/report/product_change_impact_template.xml @@ -526,538 +526,356 @@ style="margin: auto; border: none;"/> - - - - - - - - - - -
- - Affected child Products - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - + + + @@ -1065,17 +883,15 @@ -
LevelNameCodeRevisionStateImage
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - ↳ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - ↳ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - ↳ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - ↳ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - ↳ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - ↳ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +
+ + - + style='font-size:20px; color:rgb(1 88 92); padding-left: 160px;'> + ↳ - - - - -
- - - - ↳ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + - + style='font-size:20px; color:rgb(1 88 92); padding-left: 180px;'> + ↳ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + ↳ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + ↳ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + ↳ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
- -
- -
+
Affected Attachments
-
+
@@ -1148,6 +964,22 @@
Doc Name
+ +
+ No affected products and attachments found at the moment. +
+ +
+ No affected products found at the moment. +
+
+ No affected attachments found at the moment. +
+ +