[ADD] MRP: Add pdf viewer widget to view 'pdf' work instruction of workorder.
This commit is contained in:
committed by
Josse Colpaert
parent
e2fb1cb6ce
commit
89c78e40cb
@@ -66,6 +66,7 @@ Dashboard / Reports for MRP will include:
|
||||
'demo': [
|
||||
'data/mrp_demo.xml',
|
||||
'data/mrp_lot_demo.yml'],
|
||||
'qweb': ['static/src/xml/mrp.xml'],
|
||||
'test': [],
|
||||
'application': True,
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@
|
||||
<field name="name">Manual Assembly</field>
|
||||
<field name="time_cycle">60</field>
|
||||
<field name="sequence">5</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<record id="mrp_routing_workcenter_1" model="mrp.routing.workcenter">
|
||||
@@ -99,7 +99,7 @@
|
||||
<field name="name">Long time assembly</field>
|
||||
<field name="time_cycle">180</field>
|
||||
<field name="sequence">15</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/cutting-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/cutting-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<record id="mrp_routing_workcenter_3" model="mrp.routing.workcenter">
|
||||
@@ -108,7 +108,7 @@
|
||||
<field name="name">Testing</field>
|
||||
<field name="time_cycle">60</field>
|
||||
<field name="sequence">10</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<record id="mrp_routing_workcenter_4" model="mrp.routing.workcenter">
|
||||
@@ -117,7 +117,7 @@
|
||||
<field name="name">Packing</field>
|
||||
<field name="time_cycle">30</field>
|
||||
<field name="sequence">5</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/cutting-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/cutting-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<record id="mrp_routing_workcenter_2" model="mrp.routing.workcenter">
|
||||
@@ -126,7 +126,7 @@
|
||||
<field name="time_cycle">120</field>
|
||||
<field name="sequence">5</field>
|
||||
<field name="name">Manual Assembly</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<record id="mrp_routing_workcenter_5" model="mrp.routing.workcenter">
|
||||
@@ -135,7 +135,7 @@
|
||||
<field name="time_cycle">120</field>
|
||||
<field name="sequence">10</field>
|
||||
<field name="name">Cutting</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/cutting-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/cutting-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<record id="mrp_routing_workcenter_6" model="mrp.routing.workcenter">
|
||||
@@ -144,7 +144,7 @@
|
||||
<field name="time_cycle">120</field>
|
||||
<field name="sequence">15</field>
|
||||
<field name="name">Drilling</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/drill-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/drill-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<record id="mrp_routing_workcenter_7" model="mrp.routing.workcenter">
|
||||
@@ -153,7 +153,7 @@
|
||||
<field name="time_cycle">120</field>
|
||||
<field name="sequence">20</field>
|
||||
<field name="name">Assembly</field>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.jpg"/>
|
||||
<field name="worksheet" type="base64" file="mrp/static/img/assebly-worksheet.pdf"/>
|
||||
</record>
|
||||
|
||||
<!-- Resource: mrp.bom -->
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 76 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 89 KiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 66 KiB |
Binary file not shown.
@@ -5,6 +5,8 @@ var core = require('web.core');
|
||||
var common = require('web.form_common');
|
||||
var Model = require('web.Model');
|
||||
var time = require('web.time');
|
||||
var utils = require('web.utils');
|
||||
var FieldBinaryFile = core.form_widget_registry.get('binary');
|
||||
|
||||
var _t = core._t;
|
||||
|
||||
@@ -72,6 +74,74 @@ var TimeCounter = common.AbstractField.extend(common.ReinitializeFieldMixin, {
|
||||
},
|
||||
});
|
||||
|
||||
core.form_widget_registry.add('bullet_state', SetBulletStatus)
|
||||
.add('mrp_time_counter', TimeCounter);
|
||||
var FieldPdfViewer = FieldBinaryFile.extend({
|
||||
template: 'FieldPdfViewer',
|
||||
init: function(){
|
||||
this._super.apply(this, arguments);
|
||||
this.PDFViewerApplication = false;
|
||||
},
|
||||
get_uri: function(){
|
||||
var query_obj = {
|
||||
model: this.view.dataset.model,
|
||||
field: this.name,
|
||||
id: this.view.datarecord.id
|
||||
};
|
||||
var query_string = $.param(query_obj);
|
||||
var url = encodeURIComponent('/web/image?' + query_string);
|
||||
var viewer_url = '/web/static/lib/pdfjs/web/viewer.html?file=';
|
||||
return viewer_url + url;
|
||||
},
|
||||
on_file_change: function(ev) {
|
||||
this._super.apply(this, arguments);
|
||||
if(this.PDFViewerApplication){
|
||||
var files = ev.target.files;
|
||||
if (!files || files.length === 0) {
|
||||
return;
|
||||
}
|
||||
var file = files[0];
|
||||
// TOCheck: is there requirement to fallback on FileReader if browser don't support URL
|
||||
this.PDFViewerApplication.open(URL.createObjectURL(file), 0);
|
||||
}
|
||||
},
|
||||
render_value: function() {
|
||||
var $pdf_viewer = this.$('.o_form_pdf_controls').children().add(this.$('.o_pdfview_iframe')),
|
||||
$select_upload_el = this.$('.o_select_file_button').first(),
|
||||
$iFrame = this.$('.o_pdfview_iframe'),
|
||||
value = this.get('value'),
|
||||
self = this;
|
||||
|
||||
var bin_size = utils.is_bin_size(value);
|
||||
$iFrame.on('load', function(){
|
||||
self.PDFViewerApplication = this.contentWindow.window.PDFViewerApplication;
|
||||
self.disable_buttons(this);
|
||||
});
|
||||
if (this.get("effective_readonly")) {
|
||||
if (value) {
|
||||
this.$el.off('click'); // off click event(on_save_as) of FieldBinaryFile
|
||||
$iFrame.attr('src', this.get_uri());
|
||||
}
|
||||
} else {
|
||||
if (value) {
|
||||
$pdf_viewer.removeClass('o_hidden');
|
||||
$select_upload_el.addClass('o_hidden');
|
||||
if(bin_size){
|
||||
$iFrame.attr('src', this.get_uri());
|
||||
}
|
||||
} else {
|
||||
$pdf_viewer.addClass('o_hidden');
|
||||
$select_upload_el.removeClass('o_hidden');
|
||||
}
|
||||
}
|
||||
},
|
||||
disable_buttons: function(iframe){
|
||||
if (this.get("effective_readonly")){
|
||||
$(iframe).contents().find('button#download').hide();
|
||||
}
|
||||
$(iframe).contents().find('button#openFile').hide();
|
||||
}
|
||||
|
||||
});
|
||||
core.form_widget_registry.add('bullet_state', SetBulletStatus)
|
||||
.add('mrp_time_counter', TimeCounter)
|
||||
.add('pdf_viewer', FieldPdfViewer);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
.o_form_view {
|
||||
.o_form_field_pdfviewer {
|
||||
width: 100%;
|
||||
height: 450px;
|
||||
border: 0;
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates id="template" xml:space="preserve">
|
||||
<t t-name="FieldPdfViewer">
|
||||
<div class="o_form_field_pdfviewer">
|
||||
<div t-if="!widget.get('effective_readonly')" class="o_form_pdf_controls mt8">
|
||||
<span class="o_form_binary_progress">Uploading...</span>
|
||||
<button type="button" class="btn btn-sm btn-primary o_select_file_button" title="Select">Upload your file</button>
|
||||
<button class="btn btn-sm btn-default fa fa-pencil o_select_file_button" title="Select" type="button"></button>
|
||||
<button class="btn btn-sm btn-default fa fa-trash-o o_clear_file_button" title="Clear" type="button"></button>
|
||||
</div>
|
||||
<iframe class="o_pdfview_iframe o_form_field_pdfviewer"/>
|
||||
<t t-call="HiddenInputPDFFile">
|
||||
<t t-set="fileupload_id" t-value="widget.fileupload_id"/>
|
||||
<t t-set="fileupload_style" t-translation="off">overflow-x: hidden</t>
|
||||
</t>
|
||||
</div>
|
||||
</t>
|
||||
<t t-extend="HiddenInputFile" t-name="HiddenInputPDFFile">
|
||||
<t t-jquery="input[type='file']:first" t-operation="replace">
|
||||
<input type="file" class="o_form_input_file" name="ufile" accept="application/pdf" />
|
||||
</t>
|
||||
</t>
|
||||
</templates>
|
||||
@@ -47,7 +47,7 @@
|
||||
<field name="note"/>
|
||||
</page>
|
||||
<page string="Work Sheet">
|
||||
<field name="worksheet" widget="image"/>
|
||||
<field name="worksheet" widget="pdf_viewer"/>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
<template id="assets_backend" name="mrp assets" inherit_id="web.assets_backend">
|
||||
<xpath expr="." position="inside">
|
||||
<script type="text/javascript" src="/mrp/static/src/js/mrp.js"></script>
|
||||
<link rel="stylesheet" type="text/less" href="/mrp/static/src/less/mrp.less"/>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Work Instruction" attrs="{'invisible': [('worksheet', '=', False)]}">
|
||||
<field name="worksheet" widget="image"/>
|
||||
<field name="worksheet" widget="pdf_viewer"/>
|
||||
</page>
|
||||
<page string="Current Production">
|
||||
<group>
|
||||
|
||||
Reference in New Issue
Block a user