Skip to content

Commit

Permalink
[MOD] update plm_pdf_workorder changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 16, 2025
1 parent 6e639f2 commit b6c9b64
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 107 deletions.
67 changes: 15 additions & 52 deletions plm_pdf_workorder/models/mrp_workorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,29 @@
@author: Daniel Smerghetto
"""
import base64
import io

from PyPDF2 import PdfFileMerger
from odoo import _, api, fields, models


class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"

view_plm_pdf = fields.Boolean(_("Switch PDF"))
plm_pdf = fields.Binary(_("Plm PDF"))
plm_pdf = fields.Binary(_("Plm PDF"), compute="_compute_production_pdf", store=True)
use_plm_pdf = fields.Boolean(
related="operation_id.use_plm_pdf", string=_("Use PLM PDF")
)
production_doc_ids = fields.Many2many("ir.attachment",
compute="_compute_production_doc_ids",
store=True)

def action_switch_pdf(self):
for workorder_id in self:
if not workorder_id.view_plm_pdf:
workorder_id.view_plm_pdf = not workorder_id.view_plm_pdf

if workorder_id.operation_id.use_plm_pdf: # and not workorder_id.plm_pdf:
self.fetch_release_attachment(workorder_id)
workorder_id.plm_pdf = self.fetch_release_attachment(workorder_id)

view_id = self.env["ir.model.data"]._xmlid_to_res_id(
"plm_pdf_workorder.plm_pdf_show_document_workorder"
)
ctx = self.env.context.copy()
ctx.update({"create": False, "delete": False})
return {
"type": "ir.actions.act_window",
"view_type": "form",
"view_mode": "form",
"res_model": "mrp.workorder", # name of respective model,
"target": "new",
"views": [[view_id, "form"]],
"flags": {"initial_mode": "view"},
"context": ctx,
"res_id": self.id,
"target": "new",
}
@api.depends("product_id.linkeddocuments.is_production_doc")
def _compute_production_doc_ids(self):
for rec in self:
if rec.product_id.linkeddocuments:
rec.production_doc_ids = rec.product_id.linkeddocuments.filtered(
lambda doc: doc.is_production_doc == True
)
else:
rec.production_doc_ids = False

@api.model_create_multi
def create(self, vals):
Expand All @@ -77,28 +59,9 @@ def refresh_plm_instruction_pdf(self):
self.ensure_one()
if self.operation_id.use_plm_pdf:
self.plm_pdf = base64.b64encode(self.getAttachmentWorkorderPDF())

def getAttachmentWorkorderPDF(self):
self.ensure_one()
report_model = self.env["report.plm.product_production_one_pdf_latest"]
return report_model._render_qweb_pdf(self.product_id,
checkState=True)

def fetch_release_attachment(self, workorder_id):
if self.view_plm_pdf:
attachment_ids = self.env["ir.attachment"].search(
[
("linkedcomponents", "in", workorder_id.product_id.id),
("is_production_doc", "=", True),
]
)
merger = PdfFileMerger() # Use PdfFileMerger for older versions
for attachment in attachment_ids:
pdf_bytes = base64.b64decode(attachment.datas)
pdf_stream = io.BytesIO(pdf_bytes)
merger.append(pdf_stream, import_bookmarks=False)
merged_stream = io.BytesIO()
merger.write(merged_stream)
merger.close()
return report_model._render_qweb_pdf(self.product_id, checkState=True)

return base64.b64encode(merged_stream.getvalue())
12 changes: 6 additions & 6 deletions plm_pdf_workorder/views/mrp_routing_workcenter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
<xpath expr="//field[@name='worksheet_type']" position="before">
<field name="use_plm_pdf"/>
<button name="refresh_plm_instruction_pdf"
type="object"
icon="fa-refresh"/>
type="object" icon="fa-refresh"/>
<field name="plm_pdf" invisible="use_plm_pdf == False" widget="pdf_viewer"/>
</xpath>
<xpath expr="//field[@name='worksheet_type']" position="attributes">
<attribute name="invisible">use_plm_pdf == True</attribute>
</xpath>
<xpath expr="//field[@name='worksheet']" position="attributes">
<attribute name="invisible">use_plm_pdf == True</attribute>
<attribute name="invisible">use_plm_pdf == True or worksheet_type != 'pdf'</attribute>
</xpath>
<xpath expr="//field[@name='worksheet_google_slide']" position="attributes">
<attribute name="invisible">use_plm_pdf == True</attribute>
</xpath><xpath expr="//field[@name='note']" position="attributes">
<attribute name="invisible">use_plm_pdf == True</attribute>
<attribute name="invisible">use_plm_pdf == True or worksheet_type != 'google_slide'</attribute>
</xpath>
<xpath expr="//field[@name='note']" position="attributes">
<attribute name="invisible">use_plm_pdf == True or worksheet_type != 'text'</attribute>
</xpath>
</field>
</record>
Expand Down
36 changes: 15 additions & 21 deletions plm_pdf_workorder/views/mrp_workorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,21 @@
<field name="model">mrp.workorder</field>
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='worksheet']" position="before">
<group>
<group>
<field name="view_plm_pdf" string="View PLM PDF" invisible="1"/>
<button name="refresh_plm_instruction_pdf"
type="object"
icon="fa-refresh"/>
</group>
<group>
<field name="use_plm_pdf" string="Use PLM PDF" invisible="1"/>
</group>
<group>
<button name="action_switch_pdf"
invisible="use_plm_pdf==False"
class="btn btn-primary"
type="object"
aria-label="Show plm pdf related document"
title="Pdf PLM"
string="View Plm Pdf"/>
</group>
</group>
<xpath expr="//page[@name='workorder_page_work_instruction']" position="attributes">
<attribute name="invisible">use_plm_pdf == True or not worksheet and not worksheet_google_slide and not operation_note</attribute>
</xpath>
<xpath expr="//notebook" position="inside">
<page name="plm_production_doc" string="PLM Production Doc" invisible="use_plm_pdf==False">
<field name="production_doc_ids" nolabel="1" mode="kanban"
domain="[('is_plm', '=', True), ('is_production_doc','=', True)]"
widget="hierarchy_kanban"
context="{
'odooPLM': True,
'kanban_view_ref':'plm.document_kanban_view',
'list_view_ref':'plm.ir_attachment_list',
'form_view_ref':'plm.view_attachment_form_plm_hinerit'
}"/>
</page>
</xpath>
</field>
</record>
Expand Down
53 changes: 53 additions & 0 deletions plm_pdf_workorder_enterprise/models/mrp_workorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OmniaSolutions, Open Source Management Solution
# Copyright (C) 2010-2011 OmniaSolutions (<http://www.omniasolutions.eu>). All Rights Reserved
# $Id$
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import models


class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"

def action_open_workorder_kanban(self):
view_id = self.env["ir.model.data"]._xmlid_to_res_id(
"plm.document_kanban_view"
)
ctx = self.env.context.copy()
domain = [
('is_plm', '=', True),
('is_production_doc', '=', True),
('id', 'in', self.production_doc_ids.ids)
]
ctx.update({
"create": False,
"delete": False,
'default_res_ids': self.production_doc_ids.ids
})

return {
"type": "ir.actions.act_window",
"view_type": "kanban",
"view_mode": "kanban",
'domain': domain,
"res_model": "ir.attachment",
"target": "new",
"views": [[view_id, "kanban"]],
"context": ctx,
}
43 changes: 23 additions & 20 deletions plm_pdf_workorder_enterprise/static/src/mrpWorksheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ export class PlmMrpWorksheet extends MrpWorksheet{
super.setup();
}
async clicked() {
let worksheetData = false;
const sheet = await this.props.record.model.orm.read(
"mrp.workorder",
[this.props.record.resId],
["plm_pdf"]
);
if(sheet && sheet.length !=0){

worksheetData = {
resModel: "mrp.workorder",
resId: this.props.record.resId,
resField: "plm_pdf",
value: sheet[0].plm_pdf,
page: 1,
};
this.dialog.add(MrpWorksheetDialog, {
worksheetText: markup(''),
worksheetData,
});
}
debugger;
let action_open_workorder_kanban = await this.props.record.model.orm.call("mrp.workorder", "action_open_workorder_kanban", [this.props.record.resId]);
return this.action.doAction(action_open_workorder_kanban);
// let worksheetData = false;
// const sheet = await this.props.record.model.orm.read(
// "mrp.workorder",
// [this.props.record.resId],
// ["plm_pdf"]
// );
// if(sheet && sheet.length !=0){
//
// worksheetData = {
// resModel: "mrp.workorder",
// resId: this.props.record.resId,
// resField: "plm_pdf",
// value: sheet[0].plm_pdf,
// page: 1,
// };
// this.dialog.add(MrpWorksheetDialog, {
// worksheetText: markup(''),
// worksheetData,
// });
// }
}
}
PlmMrpWorksheet.template = 'plm_pdf_workorder_enterprise.MrpWorksheet'
Expand Down
19 changes: 11 additions & 8 deletions plm_spare/views/ir_attachment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
<field name="model">ir.attachment</field>
<field name="inherit_id" ref="plm.document_kanban_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='is_linkedcomponents']" position="after">
<field string="Spare Part" name="used_for_spare" invisible="True"/>
</xpath>
<xpath expr="//td[@name='Component']" position="inside">
<div class="fa fa-gear fa-2x"
aria-label="Is A Spare Drawing"
style="color: blue;"
invisible="used_for_spare in [False]"/>
<xpath expr="//table/tr" position="inside">
<td>
Spare Part:
<field name="used_for_spare" widget="boolean_toggle"/>
</td>
<td>
<div class="fa fa-gear fa-2x"
aria-label="Is A Spare Drawing"
style="color: blue;"
invisible="used_for_spare in [False]"/>
</td>
</xpath>
</field>
</record>
Expand Down

0 comments on commit b6c9b64

Please sign in to comment.