Skip to content

Commit

Permalink
[MOD] update product change impact report
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 30, 2025
1 parent 4b1a1c1 commit e69120d
Show file tree
Hide file tree
Showing 2 changed files with 1,041 additions and 100 deletions.
36 changes: 28 additions & 8 deletions plm/report/product_change_impact_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,54 @@
from odoo import api, models


class HrHolidaySummaryReport(models.AbstractModel):
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"):

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":
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_bom_hierarchy(parent_product.id, level + 1, direction)
hierarchy["children"].append(parent_hierarchy)

return hierarchy

@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'])

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:
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,
'hierarchy_child': hierarchy_child,
'hierarchy_parent': hierarchy_parent,
'affect_attachment_ids': affect_attachment_ids,
'affect_bom_ids': affect_bom_ids,
}

return {
Expand Down
Loading

0 comments on commit e69120d

Please sign in to comment.