Skip to content

Commit

Permalink
[ADD] add product change impact report
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 29, 2025
1 parent 4b38dd9 commit 4b1a1c1
Show file tree
Hide file tree
Showing 8 changed files with 325 additions and 13 deletions.
1 change: 1 addition & 0 deletions plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions plm/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<int:id>', 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/<int:product_id>', type='http', auth='user', methods=['GET'], csrf=False)
@webservice
def get_pp_preview(self, product_id):
Expand Down
22 changes: 22 additions & 0 deletions plm/data/data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,27 @@
<field name="sequence">200</field>
<field name="change_activity_type">request</field>
</record>

<!-- generate product change impact report -->
<record id="check_product_change_impact" model="ir.actions.server">
<field name="name">Check 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>
<field name="state">code</field>
<field name="code">action = records.check_product_change_impact()</field>
</record>

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

</data>
</odoo>
9 changes: 9 additions & 0 deletions plm/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions plm/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 11 additions & 11 deletions plm/report/bom_document.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
<div class="fa fa-lock" t-esc="record_browse.checkout_user"/>
</t>
<t t-else="">
<div class="fa fa-unlock" style="color:green;"/>
<div class="fa fa-unlock" style="color:green;"/>
</t>
</td>
</td>
<td class="text-center" style="padding-top: 5px; padding-bottom: 5px;">
<img t-att-src="'/plm/ir_attachment_preview/%s' % record_browse.id" t-att-alt="record_browse.display_name" class="image_document_report"/>
</td>
Expand All @@ -69,7 +69,7 @@
</div>
</div>
</template>

<template id="report_doc_bom_line">
<t t-foreach="data['children']" t-as="child_dict">
<t t-set="record_child" t-value="child_dict['id']"/>
Expand Down Expand Up @@ -120,30 +120,30 @@
<div class="fa fa-lock" t-esc="record_child.checkout_user"/>
</t>
<t t-else="">
<div class="fa fa-unlock" style="color:green;"/>
<div class="fa fa-unlock" style="color:green;"/>
</t>
</td>
</td>
<td class="text-center" style="padding-top: 5px; padding-bottom: 5px;">
<img t-att-src="'/plm/ir_attachment_preview/%s' % record_child.id" class="image_document_report" loading="lazy"/>
<img t-att-src="'/plm/ir_attachment_preview/%s' % record_child.id" class="image_document_report" loading="lazy"/>
</td>
</tr>
<div t-esc="child_dict['report_obj'].get_doc_bom(record_child, record_child_level)"/>
</t>
</template>

<template id="docuemnt_state_row">
<td class="text-center">
<b>
<t t-if="state == 'draft'"><span style="color: rgb(110, 51, 197);padding-left: 5px;"><t t-esc="state"/></span></t>
<t t-elif="state == 'confirmed'"><span style="color: blue;padding-left: 5px;"><t t-esc="state"/></span></t>
<t t-elif="state == 'released'"><span style="color: rgba(0, 170, 34, 0.66);padding-left: 5px;"><t t-esc="state"/></span></t>
<t t-elif="state == 'undermodify'"><span style="color: rgb(218, 159, 34);padding-left: 5px;"><t t-esc="state"/></span></t>
<t t-elif="state == 'undermodify'"><span style="color: rgb(218, 159, 34);padding-left: 5px;"><t t-esc="state"/></span></t>
<t t-elif="state == 'obsoleted'"><span style="color: rgb(231, 43, 26);padding-left: 5px;"><t t-esc="state"/></span></t>
<t t-else=""><span style="color: black;padding-left: 5px;"><t t-esc="state"/></span></t>
</b>
</td>
</template>

<record id="paperformat_doc_structure" model="report.paperformat">
<field name="name">Paperformat Doc Structure</field>
<field name="default" eval="True"/>
Expand Down Expand Up @@ -172,7 +172,7 @@
</t>
</t>
</template>

<record id="action_report_doc_structure" model="ir.actions.report">
<field name="name">Document structure</field>
<field name="model">ir.attachment</field>
Expand All @@ -185,4 +185,4 @@
<field name="binding_type">report</field>
</record>

</odoo>
</odoo>
38 changes: 38 additions & 0 deletions plm/report/product_change_impact_report.py
Original file line number Diff line number Diff line change
@@ -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,
}
Loading

0 comments on commit 4b1a1c1

Please sign in to comment.