Skip to content

Commit

Permalink
[MOD] add product image to bom overview
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 6, 2025
1 parent fbd328d commit 3c9275a
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 10 deletions.
2 changes: 2 additions & 0 deletions plm/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
"web.assets_backend": [
"plm/static/src/css/component_kanban.css",
"plm/static/src/css/color_fields_tree.css",
"plm/static/src/js/mrp_bom_overview_line.js",
"plm/static/src/xml/mrp_bom_overview_table_inherit.xml",
],
'web.report_assets_common': [
"plm/static/src/scss/document_bom.scss",
Expand Down
18 changes: 9 additions & 9 deletions plm/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def wrap(*args, **kw):
except Exception as e:
logging.error(e)
return Response(response=f"{e}", status=500)
return wrap
return wrap

class UploadDocument(Controller):

@route('/plm_document_upload/isalive', type='http', auth='none', methods=['GET'], csrf=False)
Expand Down Expand Up @@ -87,8 +87,8 @@ def upload(self,
logging.info('upload %r' % (doc_id))
return Response('Upload succeeded', status=200)
logging.info('no upload %r' % (doc_id))
return Response('Failed upload', status=400)
return Response('Failed upload', status=400)

@route('/plm_document_upload/download', type='http', auth='user', methods=['GET'])
@webservice
def download(self,
Expand Down Expand Up @@ -137,7 +137,7 @@ def upload_preview(self,

@route('/plm_document_upload/zip_archive', type='http', auth='user', methods=['POST'], csrf=False)
@webservice
def upload_zip(self,
def upload_zip(self,
attachment_id=None,
filename='', **kw):
logging.info('start upload zip %r' % (attachment_id))
Expand Down Expand Up @@ -176,7 +176,7 @@ def upload_zip(self,
if not link_id:
request.env['ir.attachment.relation'].create({'parent_id': from_ir_attachment_id.id,
'child_id': zip_ir_attachment_id.id,
'link_kind': 'PkgTree'})
'link_kind': 'PkgTree'})
return Response('Zip Upload succeeded', status=200)
logging.info('Zip no upload %r' % (attachment_id))
return Response('Zip Failed upload', status=400)
Expand Down Expand Up @@ -208,7 +208,7 @@ def get_files_write_time(self,
attachment_brws.name,
attachment_brws.write_date.strftime(DEFAULT_SERVER_DATETIME_FORMAT)))
return Response(json.dumps(out))


@route('/plm_document_upload/extra_file', type='http', auth='user', methods=['POST'], csrf=False)
@webservice
Expand Down Expand Up @@ -247,7 +247,7 @@ def upload_extra_file(self,
if not link_id:
request.env['ir.attachment.relation'].create({'parent_id': related_attachment_id,
'child_id': ir_attachment_id.id,
'link_kind': 'ExtraTree'})
'link_kind': 'ExtraTree'})
if product_id:
product_id = request.env['product.product'].browse(product_id)
request.env['plm.component.document.rel'].createFromIds(product_id, ir_attachment_id)
Expand Down Expand Up @@ -282,7 +282,7 @@ def get_printout(self, id):
if ir_attachement_id.printout:
print_out_data = request.env['report.plm.ir_attachment_pdf']._render_qweb_pdf(ir_attachement_id)
print_out_data = print_out_data[0]
if print_out_data:
if print_out_data:
headers = [('Content-Type', 'application/pdf'),
('Content-Length', len(print_out_data)),
('Content-Disposition', f'inline; filename="{ir_attachement_id.engineering_code}_{ir_attachement_id.engineering_revision}.pdf"')]
Expand Down
3 changes: 2 additions & 1 deletion plm/report/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
from . import bom_document
from . import product_report_document
from . import bom_structure
from . import mrp_report_bom_structure



#import new_reports # To Delete when reports are working
#import new_reports # To Delete when reports are working
15 changes: 15 additions & 0 deletions plm/report/mrp_report_bom_structure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from odoo import models


class ReportBomStructure(models.AbstractModel):
_inherit = 'report.mrp.report_bom_structure'

def _get_component_data(self, parent_bom, parent_product, warehouse, bom_line, line_quantity, level, index,
product_info, ignore_stock=False):

res = super()._get_component_data(parent_bom, parent_product, warehouse, bom_line, line_quantity, level, index,
product_info, ignore_stock)
res['image_component']= bom_line.product_id.image_1920

return res
14 changes: 14 additions & 0 deletions plm/static/src/js/mrp_bom_overview_line.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @odoo-module */

import { patch } from "@web/core/utils/patch";
import { BomOverviewLine } from "@mrp/components/bom_overview_line/mrp_bom_overview_line";

patch(BomOverviewLine.prototype, {
setup() {
super.setup();
this.image_data = false;
if(this.data && this.data.image_component){
this.image_data = 'data:image/png;base64, ' + this.data.image_component
}
}
});
18 changes: 18 additions & 0 deletions plm/static/src/xml/mrp_bom_overview_table_inherit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="plm.BomOverviewTable" t-inherit="mrp.BomOverviewTable" t-inherit-mode="extension">
<xpath expr="//th[@name='th_mrp_bom_h']" position="before">
<th name="th_mrp_bom_p_i">Image</th>
</xpath>
<xpath expr="//tfoot/tr/td" position="before">
<td/>
</xpath>
</t>
<t t-name="plm.BomOverviewLine" t-inherit="mrp.BomOverviewLine" t-inherit-mode="extension">
<xpath expr="//td" position="before">
<td name="td_mrp_bom">
<img t-if="image_data" t-att-src="this.image_data" width="50"/>
</td>
</xpath>
</t>
</templates>

0 comments on commit 3c9275a

Please sign in to comment.