Skip to Content
Menu
This question has been flagged
2 Replies
6840 Views

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'

}

Avatar
Discard
Best Answer

You have return stock piking action that's why it is showing you same record.

You should return action as following :

return

{

    'type' : 'ir.actions.act_url','url': 

    'web/content/?model=stock.picking&field=excel_file&download=true&id=%s&filename=excel_file.xls'%(self.id),

    'target': 'new',

}


Avatar
Discard
Best Answer

Hi,

hope this link helps: https://stackoverflow.com/questions/37651058/how-can-i-generate-xls-report-in-odoo

Avatar
Discard
Related Posts Replies Views Activity
1
Jan 19
1782
3
Mar 18
14100
1
Sep 17
2275
3
Jan 18
18951
2
Jul 22
7008