Skip to content

Commit

Permalink
[MOD] add kanban view for poduction document in workorder
Browse files Browse the repository at this point in the history
  • Loading branch information
jayraj-omnia committed Jan 17, 2025
1 parent b6c9b64 commit de478bd
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 103 deletions.
20 changes: 2 additions & 18 deletions plm_pdf_workorder/models/mrp_routing_workcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,10 @@
Created on Mar 30, 2016
@author: Daniel Smerghetto
"""
from odoo import _, api, fields, models
from odoo import _, fields, models


class MrpRoutingWorkcenter(models.Model):
_inherit = "mrp.routing.workcenter"

use_plm_pdf = fields.Boolean(_("Use PLM PDF"))
plm_pdf = fields.Binary(_("Plm PDF"), compute="_compute_plm_pdf_data")

def refresh_plm_instruction_pdf(self):
self.ensure_one()
for workorder_id in self.workorder_ids.filtered(lambda x: x.use_plm_pdf):
workorder_id.refresh_plm_instruction_pdf()

def _compute_plm_pdf_data(self):
workorder_id = self.env["mrp.workorder"].search([
("operation_id", "in", self.ids)
], limit=1)
for rec in self:
if rec.use_plm_pdf:
rec.plm_pdf = workorder_id.plm_pdf
else:
rec.plm_pdf = False
use_plm_docs = fields.Boolean(_("Use PLM Docs"))
36 changes: 9 additions & 27 deletions plm_pdf_workorder/models/mrp_workorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
class MrpWorkorder(models.Model):
_inherit = "mrp.workorder"

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")
use_plm_docs = fields.Boolean(
related="operation_id.use_plm_docs", string=_("Use PLM Docs")
)
production_doc_ids = fields.Many2many("ir.attachment",
compute="_compute_production_doc_ids",
Expand All @@ -41,27 +40,10 @@ class MrpWorkorder(models.Model):
@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):
ret = super(MrpWorkorder, self).create(vals)
for r in ret:
r.refresh_plm_instruction_pdf()
return ret

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)

if rec.use_plm_docs:
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
2 changes: 1 addition & 1 deletion plm_pdf_workorder/views/ir_attachment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<field name="arch" type="xml">
<xpath expr="//button[@name='related_not_update']" position="after">
<field name="is_production_doc" widget="boolean_toggle"/>
<field name="doc_seq"/>
<field name="doc_seq" invisible="1"/>
</xpath>
</field>
</record>
Expand Down
16 changes: 8 additions & 8 deletions plm_pdf_workorder/views/mrp_routing_workcenter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@
<field name="inherit_id" ref="mrp.mrp_routing_workcenter_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='worksheet_type']" position="before">
<field name="use_plm_pdf"/>
<button name="refresh_plm_instruction_pdf"
type="object" icon="fa-refresh"/>
<field name="plm_pdf" invisible="use_plm_pdf == False" widget="pdf_viewer"/>
<field name="use_plm_docs"/>
<!-- <button name="refresh_plm_instruction_pdf"-->
<!-- type="object" icon="fa-refresh"/>-->
<!-- <field name="plm_pdf" invisible="use_plm_docs == False" widget="pdf_viewer"/>-->
</xpath>
<xpath expr="//field[@name='worksheet_type']" position="attributes">
<attribute name="invisible">use_plm_pdf == True</attribute>
<attribute name="invisible">use_plm_docs == True</attribute>
</xpath>
<xpath expr="//field[@name='worksheet']" position="attributes">
<attribute name="invisible">use_plm_pdf == True or worksheet_type != 'pdf'</attribute>
<attribute name="invisible">use_plm_docs == True or worksheet_type != 'pdf'</attribute>
</xpath>
<xpath expr="//field[@name='worksheet_google_slide']" position="attributes">
<attribute name="invisible">use_plm_pdf == True or worksheet_type != 'google_slide'</attribute>
<attribute name="invisible">use_plm_docs == 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>
<attribute name="invisible">use_plm_docs == True or worksheet_type != 'text'</attribute>
</xpath>
</field>
</record>
Expand Down
22 changes: 11 additions & 11 deletions plm_pdf_workorder/views/mrp_workorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
<field name="inherit_id" ref="mrp.mrp_production_workorder_form_view_inherit"/>
<field name="arch" type="xml">
<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>
<attribute name="invisible">use_plm_docs == 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">
<page name="plm_production_doc" string="PLM Production Doc" invisible="use_plm_docs==False">
<field name="production_doc_ids" nolabel="1" mode="kanban"
domain="[('is_plm', '=', True), ('is_production_doc','=', True)]"
widget="hierarchy_kanban"
Expand All @@ -25,14 +25,14 @@
</field>
</record>

<record id="plm_pdf_show_document_workorder" model="ir.ui.view">
<field name="name">plm.pdf.show.document.workorder</field>
<field name="model">mrp.workorder</field>
<field name="arch" type="xml">
<form string="Plm Worksheet" create="false" edit="false">
<field name="plm_pdf" widget="pdf_viewer" readonly="True"/>
</form>
</field>
</record>
<!-- <record id="plm_pdf_show_document_workorder" model="ir.ui.view">-->
<!-- <field name="name">plm.pdf.show.document.workorder</field>-->
<!-- <field name="model">mrp.workorder</field>-->
<!-- <field name="arch" type="xml">-->
<!-- <form string="Plm Worksheet" create="false" edit="false">-->
<!-- <field name="plm_pdf" widget="pdf_viewer" readonly="True"/>-->
<!-- </form>-->
<!-- </field>-->
<!-- </record>-->
</data>
</odoo>
2 changes: 2 additions & 0 deletions plm_pdf_workorder_enterprise/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- encoding: utf-8 -*-
from . import models
2 changes: 2 additions & 0 deletions plm_pdf_workorder_enterprise/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# -*- encoding: utf-8 -*-
from . import mrp_workorder
8 changes: 3 additions & 5 deletions plm_pdf_workorder_enterprise/models/mrp_workorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ def action_open_workorder_kanban(self):
"plm.document_kanban_view"
)
ctx = self.env.context.copy()
domain = [
('is_plm', '=', True),
('is_production_doc', '=', True),
('id', 'in', self.production_doc_ids.ids)
]
domain = [('is_plm', '=', True),
('is_production_doc', '=', True),
('id', 'in', self.production_doc_ids.ids)]
ctx.update({
"create": False,
"delete": False,
Expand Down
21 changes: 13 additions & 8 deletions plm_pdf_workorder_enterprise/static/src/mrpDisplayRecord.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@
<templates xml:space="preserve">

<t t-inherit="mrp_workorder.MrpDisplayRecord" t-inherit-mode="extension">
<xpath expr="//div[hasclass('o_mrp_display_record')]//ul[hasclass('list-group')]//MrpWorksheet"
position="after">
<PlmMrpWorksheet t-if="showWorksheetCheck" record="props.record" clickable="true"/>
<xpath expr="//div[hasclass('o_mrp_display_record')]//ul[hasclass('list-group')]//MrpWorksheet" position="after">
<PlmMrpWorksheet record="props.record" clickable="true"/>
</xpath>
</t>

<t t-name="plm_pdf_workorder_enterprise.MrpWorksheet"
t-inherit="mrp_workorder.MrpWorksheet"
t-inherit-mode="primary">
<xpath expr="//li//span" position="replace">
<span>Plm WorkSheet</span>
<t t-name="plm_pdf_workorder_enterprise.MrpWorksheet" t-inherit="mrp_workorder.MrpWorksheet" t-inherit-mode="primary">
<xpath expr="//li" position="replace">
<li t-if="showPlmDocCheck"
t-on-click="clicked"
class="o_mrp_record_line list-group-item d-flex justify-content-between align-items-center">
<span >Plm WorkSheet</span>
<div class="btn">
<i class="fa fa-lg fa-lightbulb-o"/>
</div>
</li>
</xpath>
</t>

</templates>
46 changes: 21 additions & 25 deletions plm_pdf_workorder_enterprise/static/src/mrpWorksheet.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
/** @odoo-module **/

import { MrpWorksheet } from "@mrp_workorder/mrp_display/mrp_record_line/mrp_worksheet";
import { MrpWorksheetDialog } from "@mrp_workorder/mrp_display/dialog/mrp_worksheet_dialog";
import { MrpDisplayRecord } from '@mrp_workorder/mrp_display/mrp_display_record'
import { markup } from "@odoo/owl";

export class PlmMrpWorksheet extends MrpWorksheet{
setup(){
async setup(){
super.setup();
this.showPlmDocs = false;
if(this.props && this.props.record && this.props.record.data && this.props.record.data.operation_id && this.props.record.data.operation_id.length !=0){
let displayDocs = await this.props.record.model.orm.read(
"mrp.routing.workcenter",
[ this.props.record.data.operation_id[0]],
["use_plm_docs"]
);
if(displayDocs.length !=0){
this.showPlmDocs = displayDocs[0].use_plm_docs;
this.render();
}
}
}

get showPlmDocCheck() {
return this.showPlmDocs;
}

async clicked() {
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'

MrpDisplayRecord.components = {
...MrpDisplayRecord.components,
PlmMrpWorksheet,
Expand Down

0 comments on commit de478bd

Please sign in to comment.