Added module web_printscreen_zb
parent
3850254f1a
commit
5c5e245f74
|
|
@ -0,0 +1,27 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013 ZestyBeanz Technologies Pvt. Ltd.
|
||||||
|
# (http://wwww.zbeanztech.com)
|
||||||
|
# contact@zbeanztech.com
|
||||||
|
# prajul@zbeanztech.com
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
import trml2pdf
|
||||||
|
import controllers
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
@ -0,0 +1,41 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013 ZestyBeanz Technologies Pvt. Ltd.
|
||||||
|
# (http://wwww.zbeanztech.com)
|
||||||
|
# contact@zbeanztech.com
|
||||||
|
# prajul@zbeanztech.com
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
{
|
||||||
|
'name': 'Web Printscreen ZB',
|
||||||
|
'version': '1.0',
|
||||||
|
'category': 'Web',
|
||||||
|
'description': """
|
||||||
|
Module to export current active tree view in to excel report
|
||||||
|
""",
|
||||||
|
'author': 'Zesty Beanz Technologies',
|
||||||
|
'website': 'http://www.zbeanztech.com',
|
||||||
|
'depends': ['web'],
|
||||||
|
'data': ['views/web_printscreen_zb.xml'],
|
||||||
|
'qweb': ['static/src/xml/web_printscreen_export.xml'],
|
||||||
|
'installable': True,
|
||||||
|
'auto_install': False,
|
||||||
|
'web_preload': False,
|
||||||
|
}
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
@ -0,0 +1,185 @@
|
||||||
|
# -*- encoding: utf-8 -*-
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Copyright (c) 2013 ZestyBeanz Technologies Pvt. Ltd.
|
||||||
|
# (http://wwww.zbeanztech.com)
|
||||||
|
# contact@zbeanztech.com
|
||||||
|
# prajul@zbeanztech.com
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
except ImportError:
|
||||||
|
import simplejson as json
|
||||||
|
import openerp.addons.web.http as openerpweb
|
||||||
|
from openerp.addons.web.controllers.main import ExcelExport
|
||||||
|
from openerp.addons.web.controllers.main import Export
|
||||||
|
import re
|
||||||
|
from cStringIO import StringIO
|
||||||
|
from lxml import etree
|
||||||
|
import trml2pdf
|
||||||
|
import time, os
|
||||||
|
import locale
|
||||||
|
import openerp.tools as tools
|
||||||
|
try:
|
||||||
|
import xlwt
|
||||||
|
except ImportError:
|
||||||
|
xlwt = None
|
||||||
|
|
||||||
|
class ZbExcelExport(ExcelExport):
|
||||||
|
_cp_path = '/web/export/zb_excel_export'
|
||||||
|
|
||||||
|
def from_data(self, fields, rows):
|
||||||
|
workbook = xlwt.Workbook()
|
||||||
|
worksheet = workbook.add_sheet('Sheet 1')
|
||||||
|
style = xlwt.easyxf('align: wrap yes')
|
||||||
|
font = xlwt.Font()
|
||||||
|
font.bold = True
|
||||||
|
style.font = font
|
||||||
|
ignore_index = []
|
||||||
|
count = 0
|
||||||
|
for i, fieldname in enumerate(fields):
|
||||||
|
if fieldname.get('header_data_id', False):
|
||||||
|
field_name = fieldname.get('header_name', '')
|
||||||
|
worksheet.write(0, i-count, field_name, style)
|
||||||
|
worksheet.col(i).width = 8000
|
||||||
|
else:
|
||||||
|
count += 1
|
||||||
|
ignore_index.append(i)
|
||||||
|
style = xlwt.easyxf('align: wrap yes')
|
||||||
|
bold_style = xlwt.easyxf('align: wrap yes')
|
||||||
|
font = xlwt.Font()
|
||||||
|
font.bold = True
|
||||||
|
bold_style.font = font
|
||||||
|
for row_index, row in enumerate(rows):
|
||||||
|
count = 0
|
||||||
|
for cell_index, cell_value in enumerate(row):
|
||||||
|
if cell_index not in ignore_index:
|
||||||
|
cell_style = style
|
||||||
|
if cell_value.get('bold', False):
|
||||||
|
cell_style = bold_style
|
||||||
|
cellvalue = cell_value.get('data', '')
|
||||||
|
if isinstance(cellvalue, basestring):
|
||||||
|
cellvalue = re.sub("\r", " ", cellvalue)
|
||||||
|
if cell_value.get('number', False) and cellvalue:
|
||||||
|
cellvalue = float(cellvalue)
|
||||||
|
if cellvalue is False: cellvalue = None
|
||||||
|
worksheet.write(row_index + 1, cell_index - count, cellvalue, cell_style)
|
||||||
|
else:
|
||||||
|
count += 1
|
||||||
|
fp = StringIO()
|
||||||
|
workbook.save(fp)
|
||||||
|
fp.seek(0)
|
||||||
|
data = fp.read()
|
||||||
|
fp.close()
|
||||||
|
return data
|
||||||
|
|
||||||
|
@openerpweb.httprequest
|
||||||
|
def index(self, req, data, token):
|
||||||
|
data = json.loads(data)
|
||||||
|
return req.make_response(
|
||||||
|
self.from_data(data.get('headers', []), data.get('rows', [])),
|
||||||
|
headers=[
|
||||||
|
('Content-Disposition', 'attachment; filename="%s"'
|
||||||
|
% data.get('model', 'Export.xls')),
|
||||||
|
('Content-Type', self.content_type)
|
||||||
|
],
|
||||||
|
cookies={'fileToken': token}
|
||||||
|
)
|
||||||
|
|
||||||
|
class ExportPdf(Export):
|
||||||
|
_cp_path = '/web/export/zb_pdf'
|
||||||
|
fmt = {
|
||||||
|
'tag': 'pdf',
|
||||||
|
'label': 'PDF',
|
||||||
|
'error': None
|
||||||
|
}
|
||||||
|
|
||||||
|
@property
|
||||||
|
def content_type(self):
|
||||||
|
return 'application/pdf'
|
||||||
|
|
||||||
|
def filename(self, base):
|
||||||
|
return base + '.pdf'
|
||||||
|
|
||||||
|
def from_data(self, uid, fields, rows, company_name):
|
||||||
|
pageSize=[210.0,297.0]
|
||||||
|
new_doc = etree.Element("report")
|
||||||
|
config = etree.SubElement(new_doc, 'config')
|
||||||
|
def _append_node(name, text):
|
||||||
|
n = etree.SubElement(config, name)
|
||||||
|
n.text = text
|
||||||
|
_append_node('date', time.strftime(str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))))
|
||||||
|
_append_node('PageSize', '%.2fmm,%.2fmm' % tuple(pageSize))
|
||||||
|
_append_node('PageWidth', '%.2f' % (pageSize[0] * 2.8346,))
|
||||||
|
_append_node('PageHeight', '%.2f' %(pageSize[1] * 2.8346,))
|
||||||
|
_append_node('PageFormat', 'a4')
|
||||||
|
_append_node('header-date', time.strftime(str(locale.nl_langinfo(locale.D_FMT).replace('%y', '%Y'))))
|
||||||
|
_append_node('company', company_name)
|
||||||
|
l = []
|
||||||
|
t = 0
|
||||||
|
temp = []
|
||||||
|
tsum = []
|
||||||
|
skip_index = []
|
||||||
|
header = etree.SubElement(new_doc, 'header')
|
||||||
|
i = 0
|
||||||
|
for f in fields:
|
||||||
|
if f.get('header_data_id', False):
|
||||||
|
value = f.get('header_name', "")
|
||||||
|
field = etree.SubElement(header, 'field')
|
||||||
|
field.text = tools.ustr(value)
|
||||||
|
else:
|
||||||
|
skip_index.append(i)
|
||||||
|
i += 1
|
||||||
|
lines = etree.SubElement(new_doc, 'lines')
|
||||||
|
for row_lines in rows:
|
||||||
|
node_line = etree.SubElement(lines, 'row')
|
||||||
|
j = 0
|
||||||
|
for row in row_lines:
|
||||||
|
if not j in skip_index:
|
||||||
|
para = "yes"
|
||||||
|
tree = "no"
|
||||||
|
value = row.get('data', '')
|
||||||
|
if row.get('bold', False):
|
||||||
|
para = "group"
|
||||||
|
if row.get('number', False):
|
||||||
|
tree = "float"
|
||||||
|
col = etree.SubElement(node_line, 'col', para=para, tree=tree)
|
||||||
|
col.text = tools.ustr(value)
|
||||||
|
j += 1
|
||||||
|
transform = etree.XSLT(
|
||||||
|
etree.parse(os.path.join(tools.config['root_path'],
|
||||||
|
'addons/base/report/custom_new.xsl')))
|
||||||
|
rml = etree.tostring(transform(new_doc))
|
||||||
|
self.obj = trml2pdf.parseNode(rml, title='Printscreen')
|
||||||
|
return self.obj
|
||||||
|
|
||||||
|
class ZbPdfExport(ExportPdf):
|
||||||
|
_cp_path = '/web/export/zb_pdf_export'
|
||||||
|
|
||||||
|
@openerpweb.httprequest
|
||||||
|
def index(self, req, data, token):
|
||||||
|
data = json.loads(data)
|
||||||
|
uid = data.get('uid', False)
|
||||||
|
return req.make_response(self.from_data(uid, data.get('headers', []), data.get('rows', []),
|
||||||
|
data.get('company_name','')),
|
||||||
|
headers=[('Content-Disposition',
|
||||||
|
'attachment; filename=PDF Export'),
|
||||||
|
('Content-Type', self.content_type)])
|
||||||
|
# cookies={'fileToken': long(token)})
|
||||||
|
|
||||||
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||||
|
|
@ -0,0 +1,122 @@
|
||||||
|
openerp.web_printscreen_zb = function(instance, m) {
|
||||||
|
|
||||||
|
var _t = instance.web._t;
|
||||||
|
var QWeb = instance.web.qweb;
|
||||||
|
|
||||||
|
instance.web.ListView.include({
|
||||||
|
load_list: function () {
|
||||||
|
var self = this;
|
||||||
|
this._super.apply(this, arguments);
|
||||||
|
self.$pager.find(".oe_list_button_import_excel").unbind('click').click(function(event){self.export_to_excel("excel")})
|
||||||
|
self.$pager.find(".oe_list_button_import_pdf").unbind('click').click(function(event){self.export_to_excel("pdf")})
|
||||||
|
},
|
||||||
|
export_to_excel: function(export_type) {
|
||||||
|
var self = this
|
||||||
|
var export_type = export_type
|
||||||
|
view = this.getParent()
|
||||||
|
// Find Header Element
|
||||||
|
header_eles = self.$el.find('.oe_list_header_columns')
|
||||||
|
header_name_list = []
|
||||||
|
$.each(header_eles,function(){
|
||||||
|
$header_ele = $(this)
|
||||||
|
header_td_elements = $header_ele.find('th')
|
||||||
|
$.each(header_td_elements,function(){
|
||||||
|
$header_td = $(this)
|
||||||
|
text = $header_td.text().trim() || ""
|
||||||
|
data_id = $header_td.attr('data-id')
|
||||||
|
if (text && !data_id){
|
||||||
|
data_id = 'group_name'
|
||||||
|
}
|
||||||
|
header_name_list.push({'header_name': text.trim(), 'header_data_id': data_id})
|
||||||
|
// }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
//Find Data Element
|
||||||
|
data_eles = self.$el.find('.oe_list_content > tbody > tr')
|
||||||
|
export_data = []
|
||||||
|
$.each(data_eles,function(){
|
||||||
|
data = []
|
||||||
|
$data_ele = $(this)
|
||||||
|
is_analysis = false
|
||||||
|
if ($data_ele.text().trim()){
|
||||||
|
//Find group name
|
||||||
|
group_th_eles = $data_ele.find('th')
|
||||||
|
$.each(group_th_eles,function(){
|
||||||
|
$group_th_ele = $(this)
|
||||||
|
text = $group_th_ele.text().trim() || ""
|
||||||
|
is_analysis = true
|
||||||
|
data.push({'data': text, 'bold': true})
|
||||||
|
});
|
||||||
|
data_td_eles = $data_ele.find('td')
|
||||||
|
$.each(data_td_eles,function(){
|
||||||
|
$data_td_ele = $(this)
|
||||||
|
text = $data_td_ele.text().trim() || ""
|
||||||
|
if ($data_td_ele && $data_td_ele[0].classList.contains('oe_number') && !$data_td_ele[0].classList.contains('oe_list_field_float_time')){
|
||||||
|
text = text.replace('%', '')
|
||||||
|
text = instance.web.parse_value(text, { type:"float" })
|
||||||
|
data.push({'data': text || "", 'number': true})
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
data.push({'data': text})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
export_data.push(data)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//Find Footer Element
|
||||||
|
|
||||||
|
footer_eles = self.$el.find('.oe_list_content > tfoot> tr')
|
||||||
|
$.each(footer_eles,function(){
|
||||||
|
data = []
|
||||||
|
$footer_ele = $(this)
|
||||||
|
footer_td_eles = $footer_ele.find('td')
|
||||||
|
$.each(footer_td_eles,function(){
|
||||||
|
$footer_td_ele = $(this)
|
||||||
|
text = $footer_td_ele.text().trim() || ""
|
||||||
|
if ($footer_td_ele && $footer_td_ele[0].classList.contains('oe_number')){
|
||||||
|
text = instance.web.parse_value(text, { type:"float" })
|
||||||
|
data.push({'data': text || "", 'bold': true, 'number': true})
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
data.push({'data': text, 'bold': true})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
export_data.push(data)
|
||||||
|
});
|
||||||
|
|
||||||
|
//Export to excel
|
||||||
|
$.blockUI();
|
||||||
|
if (export_type === 'excel'){
|
||||||
|
view.session.get_file({
|
||||||
|
url: '/web/export/zb_excel_export',
|
||||||
|
data: {data: JSON.stringify({
|
||||||
|
model : view.model,
|
||||||
|
headers : header_name_list,
|
||||||
|
rows : export_data,
|
||||||
|
})},
|
||||||
|
complete: $.unblockUI
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
console.log(view)
|
||||||
|
new instance.web.Model("res.users").get_func("read")(this.session.uid, ["company_id"]).then(function(res) {
|
||||||
|
new instance.web.Model("res.company").get_func("read")(res['company_id'][0], ["name"]).then(function(result) {
|
||||||
|
view.session.get_file({
|
||||||
|
url: '/web/export/zb_pdf_export',
|
||||||
|
data: {data: JSON.stringify({
|
||||||
|
uid: view.session.uid,
|
||||||
|
model : view.model,
|
||||||
|
headers : header_name_list,
|
||||||
|
rows : export_data,
|
||||||
|
company_name: result['name']
|
||||||
|
})},
|
||||||
|
complete: $.unblockUI
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<templates id="template" xml:space="preserve">
|
||||||
|
<t t-extend="ViewPager">
|
||||||
|
<t t-jquery=".oe_pager_value" t-operation="prepend">
|
||||||
|
<a t-if="(widget.ViewManager && widget.ViewManager.active_view) === 'list'"
|
||||||
|
class="oe_bold oe_list_button_import_pdf"
|
||||||
|
id="button_export_pdf"
|
||||||
|
href="#">PDF</a>
|
||||||
|
<label t-if="(widget.ViewManager && widget.ViewManager.active_view) === 'list'">or</label>
|
||||||
|
<a t-if="(widget.ViewManager && widget.ViewManager.active_view) === 'list'"
|
||||||
|
class="oe_bold oe_list_button_import_excel"
|
||||||
|
id="button_export_excel"
|
||||||
|
href="#">Excel</a>
|
||||||
|
</t>
|
||||||
|
</t>
|
||||||
|
</templates>
|
||||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- vim:fdn=3:
|
||||||
|
-->
|
||||||
|
<openerp>
|
||||||
|
<data>
|
||||||
|
<template id="assets_backend" name="web_printscreen_zb assets" inherit_id="web.assets_backend">
|
||||||
|
<xpath expr="." position="inside">
|
||||||
|
<script type="text/javascript" src="/web_printscreen_zb/static/src/js/web_printscreen_export.js"></script>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
</data>
|
||||||
|
</openerp>
|
||||||
|
|
@ -117,7 +117,8 @@ class Config():
|
||||||
'cam_custom',
|
'cam_custom',
|
||||||
'cam_reports',
|
'cam_reports',
|
||||||
'account_cancel',
|
'account_cancel',
|
||||||
'cam_invoice_skonto',
|
'cam_invoice_skonto',
|
||||||
|
#'web_printscreen_zb',
|
||||||
#'crm',
|
#'crm',
|
||||||
#'sale',
|
#'sale',
|
||||||
#'cam_hr_overtime',
|
#'cam_hr_overtime',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue