I need to print an excel file from form view without using wizard.The problem is that when press thegenerate_bt
,the same form view appears like a box.
Code
from odoo import models, fields, api
from odoo.tools.translate import _
from odoo.exceptions import UserError, AccessError
from datetime import datetime, timedelta
import dateutil.parser
import base64
import xlwt
from cStringIO import StringIO
from pprint import pprint
import logging
from openerp import tools
_logger = logging.getLogger(__name__)
class SerialNumberXls(models.Model):
_inherit = 'stock.picking'
excel_file = fields.Binary(string='Download Report Excel',readonly="1")
file_name = fields.Char(string='Excel File',readonly="1")
def generate_bt(self):
print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
print "hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii"
workbook= xlwt.Workbook(encoding="UTF-8")
filename='MarkupReport.xls'
sheet= workbook.add_sheet('Markup Report',cell_overwrite_ok=True)
style = xlwt.easyxf('font:name Arial,height 200;')
style2 = xlwt.easyxf('font:name Arial,height 200,bold True;align: horiz center, vert center;')
style_filter = xlwt.easyxf('font:name Arial; align: horiz center, vert center;')
style_normal_left = xlwt.easyxf('font:name Arial; align: horiz left, vert center;')
style_normal_right = xlwt.easyxf('font:name Arial; align: horiz right, vert center;')
row =0
col = 5
sheet.write(row,col,"hiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii",style2)
return {
'view_type': 'form',
"view_mode": 'form',
'res_model': 'stock.picking',
'res_id': self.id,
'type': 'ir.actions.act_window',
'target': 'new'
}