diff --git a/plm_pdf_workorder/models/mrp_workorder.py b/plm_pdf_workorder/models/mrp_workorder.py
index 3e5182ce..2eae83c7 100755
--- a/plm_pdf_workorder/models/mrp_workorder.py
+++ b/plm_pdf_workorder/models/mrp_workorder.py
@@ -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):
@@ -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())
diff --git a/plm_pdf_workorder/views/mrp_routing_workcenter.xml b/plm_pdf_workorder/views/mrp_routing_workcenter.xml
index c23a9fe9..303e3506 100755
--- a/plm_pdf_workorder/views/mrp_routing_workcenter.xml
+++ b/plm_pdf_workorder/views/mrp_routing_workcenter.xml
@@ -9,20 +9,20 @@
+ type="object" icon="fa-refresh"/>
use_plm_pdf == True
- use_plm_pdf == True
+ use_plm_pdf == True or worksheet_type != 'pdf'
- use_plm_pdf == True
-
- use_plm_pdf == True
+ use_plm_pdf == True or worksheet_type != 'google_slide'
+
+
+ use_plm_pdf == True or worksheet_type != 'text'
diff --git a/plm_pdf_workorder/views/mrp_workorder.xml b/plm_pdf_workorder/views/mrp_workorder.xml
index 97d90679..0209ac2f 100755
--- a/plm_pdf_workorder/views/mrp_workorder.xml
+++ b/plm_pdf_workorder/views/mrp_workorder.xml
@@ -6,27 +6,21 @@
mrp.workorder
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+ use_plm_pdf == True or not worksheet and not worksheet_google_slide and not operation_note
+
+
+
+
+
diff --git a/plm_pdf_workorder_enterprise/models/mrp_workorder.py b/plm_pdf_workorder_enterprise/models/mrp_workorder.py
new file mode 100644
index 00000000..e5c5aa05
--- /dev/null
+++ b/plm_pdf_workorder_enterprise/models/mrp_workorder.py
@@ -0,0 +1,53 @@
+# -*- encoding: utf-8 -*-
+##############################################################################
+#
+# OmniaSolutions, Open Source Management Solution
+# Copyright (C) 2010-2011 OmniaSolutions (). 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 .
+#
+##############################################################################
+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,
+ }
diff --git a/plm_pdf_workorder_enterprise/static/src/mrpWorksheet.js b/plm_pdf_workorder_enterprise/static/src/mrpWorksheet.js
index 485449b4..29bf6bf2 100644
--- a/plm_pdf_workorder_enterprise/static/src/mrpWorksheet.js
+++ b/plm_pdf_workorder_enterprise/static/src/mrpWorksheet.js
@@ -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'
diff --git a/plm_spare/views/ir_attachment.xml b/plm_spare/views/ir_attachment.xml
index ff1ceb69..4ea4dca6 100755
--- a/plm_spare/views/ir_attachment.xml
+++ b/plm_spare/views/ir_attachment.xml
@@ -5,14 +5,17 @@
ir.attachment
-
-
-
-
-
+
+
+ Spare Part:
+
+ |
+
+
+ |