Created
July 21, 2015 22:56
-
-
Save ovnicraft/c6cb99cf0a99f1d718bf to your computer and use it in GitHub Desktop.
override report method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import os | |
import base64 | |
import StringIO | |
import subprocess | |
from openerp.osv import osv, fields, orm | |
from openerp.addons.report_webkit.webkit_report import * | |
JAVA_CMD = 'java' | |
JAR_PATH = 'jSignPdf.jar' | |
def sign(document, file_pk12, password): | |
""" | |
Metodo que aplica la firma digital al PDF | |
java -jar JSignPdf.jar -kst PKCS12 -ksf certificado -ksp password mi_archivo.pdf | |
""" | |
xml_str = etree.tostring(xml_document, encoding='utf8', method='xml') | |
firma_path = os.path.join(os.path.dirname(__file__), JAR_PATH) | |
p = subprocess.Popen([JAVA_CMD, '-jar', firma_path, document, file_pk12, password], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
res = p.communicate() | |
return res[0] | |
class ResUser(orm.Model): | |
_inherit = 'res.users' | |
_columns = dict( | |
path_cert = fields.char('Dirección fisica del certificado'), | |
password_cert = fields.char('Password del Certificado') | |
) | |
class ReportSigned(WebKitParser): | |
def sign_document(self, cursor, uid, report): | |
user = self.pool.get('res.users').browse(cursor, uid, uid) | |
signed = sign(report, user.cert_path, user.cert_passworda) | |
return signed | |
def create_single_pdf(self, cursor, uid, ids, data, report_xml, context=None): | |
""" override to sign pdf """ | |
report, type_report = super(ReportSigned, self).create_single_pdf(cursor, uid, ids, data, report_xml, context) | |
report_signed = self.sign_document(cursor, uid, report) | |
return report_signed, type_report | |
def create(self, cursor, uid, ids, data, context=None): | |
result = super(ReportSigned, self).create(cursor, uid, ids, data, context) | |
import pdb | |
pdb.set_trace() | |
print "override" | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment