Skip to content

Commit

Permalink
[ADD] change impact report for attachemt
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 31, 2025
1 parent e69120d commit 77e1105
Show file tree
Hide file tree
Showing 8 changed files with 1,006 additions and 546 deletions.
8 changes: 5 additions & 3 deletions plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 22 additions & 1 deletion plm/data/data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<!-- generate product change impact report -->
<record id="check_product_change_impact" model="ir.actions.server">
<field name="name">Check Change Impact</field>
<field name="name">Check Product Change Impact</field>
<field name="model_id" ref="product.model_product_product"/>
<field name="binding_model_id" ref="product.model_product_product"/>
<field name="binding_view_types">form</field>
Expand All @@ -31,5 +31,26 @@
<field name="print_report_name">'product : %s Change Impact' % (object.display_name)</field>
</record>

<!-- generate attachment change impact report -->
<record id="check_attachment_change_impact" model="ir.actions.server">
<field name="name">Check Attachment Change Impact</field>
<field name="model_id" ref="model_ir_attachment"/>
<field name="binding_model_id" ref="model_ir_attachment"/>
<field name="binding_view_types">form</field>
<field name="state">code</field>
<field name="code">action = records.check_attachment_change_impact()</field>
</record>

<!-- product change impact report -->
<record id="action_report_attachment_change_impact" model="ir.actions.report">
<field name="name">Attachment Change Impact</field>
<field name="model">ir.attachment</field>
<field name="report_type">qweb-html</field>
<field name="paperformat_id" ref="plm.paperformat_doc_structure"/>
<field name="report_name">plm.attachment_change_impact_report_template</field>
<field name="report_file">plm.attachment_change_impact_report_template</field>
<field name="print_report_name">'attachment : %s change impact report' % (object.display_name)</field>
</record>

</data>
</odoo>
10 changes: 10 additions & 0 deletions plm/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
1 change: 1 addition & 0 deletions plm/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
47 changes: 47 additions & 0 deletions plm/report/attachment_change_impact_template.py
Original file line number Diff line number Diff line change
@@ -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,
}
Loading

0 comments on commit 77e1105

Please sign in to comment.